hash

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

hash

Post by Silvio.Falconi »

I must converte a xjson test into hash but i make error

Code: Select all

 #include"fivewin.ch"

Function test()
Local HData
Local ctext:= ' {"ok":true,"result":[{"update_id":54113084,'+;
'"message":{"message_id":40,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537475869,"text":"/join","entities":[{"offset":0,"length":5,"type":"bot_command"}]}},{"update_id":54113085, '+;
'"message":{"message_id":41,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537475936,"text":"test"}},{"update_id":54113086,'+;
'"message":{"message_id":42,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-237720378,"title":"testprovabotsilvio","type":"group","all_members_are_administrators":true},"date":1537476295,"left_chat_participant":{"id":651666627,"is_bot":true,"first_name":"sostituzionedocenti_bot","username":"sostituzionedocenti_bot"},"left_chat_member":{"id":651666627,"is_bot":true,"first_name":"sostituzionedocenti_bot","username":"sostituzionedocenti_bot"}}},{"update_id":54113087, '+;
'"message":{"message_id":43,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-237720378,"title":"testprovabotsilvio","type":"group","all_members_are_administrators":true},"date":1537476409,"new_chat_participant":{"id":651666627,"is_bot":true,"first_name":"sostituzionedocenti_bot","username":"sostituzionedocenti_bot"},"new_chat_member":{"id":651666627,"is_bot":true,"first_name":"sostituzionedocenti_bot","username":"sostituzionedocenti_bot"},"new_chat_members":[{"id":651666627,"is_bot":true,"first_name":"sostituzionedocenti_bot","username":"sostituzionedocenti_bot"}]}},{"update_id":54113088,  '+;
'"message":{"message_id":44,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537476423,"text":"ciao"}},{"update_id":54113089,'+;
'"message":{"message_id":45,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537476435,"text":"cc"}},{"update_id":54113090, '+;
'"message":{"message_id":46,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it-IT"},"chat":{"id":-237720378,"title":"testprovabotsilvio","type":"group","all_members_are_administrators":true},"date":1537477153,"text":"/get_my_id@sostituzionedocenti_bot","entities":[{"offset":0,"length":34,"type":"bot_command"}]}},{"update_id":54113091, '+;
'"message":{"message_id":47,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it-IT"},"chat":{"id":-237720378,"title":"testprovabotsilvio","type":"group","all_members_are_administrators":true},"date":1537477156,"text":"/get_my_id@sostituzionedocenti_bot","entities":[{"offset":0,"length":34,"type":"bot_command"}]}},{"update_id":54113092, '+;
'"message":{"message_id":48,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-237720378,"title":"testprovabotsilvio","type":"group","all_members_are_administrators":true},"date":1537477896,"migrate_to_chat_id":-1001153142939}},{"update_id":54113093,'+;
'"message":{"message_id":1,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537477896,"migrate_from_chat_id":-237720378}},{"update_id":54113094,'+;
'"message":{"message_id":49,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537477991,"text":"/help","entities":[{"offset":0,"length":5,"type":"bot_command"}]}},{"update_id":54113095,'+;
'"message":{"message_id":50,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537478002,"text":"non funziona i comandi"}},{"update_id":54113096, '+;
'"message":{"message_id":51,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537478025,"text":"fammi vede che posso fare?"}},{"update_id":54113097, '+;
'"message":{"message_id":52,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537478028,"text":"!!!"}},{"update_id":54113098, '+;
'"message":{"message_id":53,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537478044,"text":"per inserire i comandi da botfather"}},{"update_id":54113101, '+;
'"message":{"message_id":54,"from":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"chat":{"id":112607325,"first_name":"Varstahl","username":"Varstahl","type":"private"},"date":1537478429,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":54113102,'+;
'"message":{"message_id":55,"from":{"id":111707870,"is_bot":false,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","language_code":"it"},"chat":{"id":111707870,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","type":"private"},"date":1537481885,"text":"/stop","entities":[{"offset":0,"length":5,"type":"bot_command"}]}},{"update_id":54113103, '+;
'"message":{"message_id":2,"from":{"id":111707870,"is_bot":false,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483045,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":54113104,'+;
'"message":{"message_id":3,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483221,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":54113110,'+;
'"message":{"message_id":4,"from":{"id":111707870,"is_bot":false,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483317,"new_chat_participant":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"new_chat_member":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"new_chat_members":[{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"}]}},{"update_id":54113112,'+;
'"message":{"message_id":6,"from":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483333,"text":"/get_my_id@sostituzionedocenti_bot","entities":[{"offset":0,"length":34,"type":"bot_command"}]}},{"update_id":54113113,  '+;
'"message":{"message_id":7,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483341,"text":"/get_my_id@sostituzionedocenti_bot","entities":[{"offset":0,"length":34,"type":"bot_command"}]}},{"update_id":54113114,  '+;
'"message":{"message_id":8,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483342,"text":"/get_my_id@sostituzionedocenti_bot","entities":[{"offset":0,"length":34,"type":"bot_command"}]}},{"update_id":54113115, '+;
'"message":{"message_id":9,"from":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483343,"text":"/start@sostituzionedocenti_bot","entities":[{"offset":0,"length":30,"type":"bot_command"}]}},{"update_id":54113116,  '+;
'"message":{"message_id":10,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537483348,"text":"/start@sostituzionedocenti_bot","entities":[{"offset":0,"length":30,"type":"bot_command"}]}},{"update_id":54113117,  '+;
'"message":{"message_id":56,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537483362,"text":"test"}},{"update_id":54113118,'+;
'"message":{"message_id":11,"from":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537486945,"text":"/start@sostituzionedocenti_bot","entities":[{"offset":0,"length":30,"type":"bot_command"}]}},{"update_id":54113119, '+;
'"message":{"message_id":21,"from":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537487781,"left_chat_participant":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"},"left_chat_member":{"id":112607325,"is_bot":false,"first_name":"Varstahl","username":"Varstahl","language_code":"en-US"}}},{"update_id":54113120,'+;
'"message":{"message_id":25,"from":{"id":111707870,"is_bot":false,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537487816,"left_chat_participant":{"id":111707870,"is_bot":false,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","language_code":"it"},"left_chat_member":{"id":111707870,"is_bot":false,"first_name":"Diego [SkiD] IU6CRH","last_name":"Cioschi","username":"theSkiD","language_code":"it"}}},{"update_id":54113121,'+;
'"message":{"message_id":27,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537530900,"text":"/help@sostituzionedocenti_bot","entities":[{"offset":0,"length":29,"type":"bot_command"}]}},{"update_id":54113122,'+;
'"message":{"message_id":28,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537530903,"text":"/help@sostituzionedocenti_bot","entities":[{"offset":0,"length":29,"type":"bot_command"}]}},{"update_id":54113123, '+;
'"message":{"message_id":29,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":-1001153142939,"title":"testprovabotsilvio","type":"supergroup"},"date":1537530961,"text":"/help@sostituzionedocenti_bot","entities":[{"offset":0,"length":29,"type":"bot_command"}]}},{"update_id":54113124, '+;
'"message":{"message_id":59,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537545183,"text":"i comandi non funzionano perch\u00e8 lo so io  ti spiego  io creo  una lista comandi"}},{"update_id":54113125, '+;
'"message":{"message_id":60,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537552433,"text":"test"}},{"update_id":54113126, '+;
'"message":{"message_id":61,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537559510,"text":"test"}},{"update_id":54113127, '+;
'"message":{"message_id":62,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537560259,"text":"CIAO DA TOPOLINO"}},{"update_id":54113128,'+;
'"message":{"message_id":63,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537561361,"text":"/START","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":54113129, '+;
'"message":{"message_id":64,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537561370,"text":"/accetta","entities":[{"offset":0,"length":8,"type":"bot_command"}]}},{"update_id":54113130, '+;
'"message":{"message_id":65,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537561372,"text":"/accetta","entities":[{"offset":0,"length":8,"type":"bot_command"}]}},{"update_id":54113131,  '+;
'"message":{"message_id":66,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537561378,"text":"/lista","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":54113132,   '+;
'"message":{"message_id":67,"from":{"id":612815965,"is_bot":false,"first_name":"Topolino","username":"ittopolino","language_code":"it"},"chat":{"id":612815965,"first_name":"Topolino","username":"ittopolino","type":"private"},"date":1537562107,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}}]}  '



HData:= strtoHasharray(ctext)

xbrowser hdata

return nil

function StrToHashArray( cStr )

   local hHash, aHash

   cStr  := CharRepl( "[]", RangeRem( 1, 31, cStr ), "{}" )
   do while '" :' $ cStr
      StrTran( cStr, '" :', '":' )
   enddo
   cStr  := (StrTran( cStr, '":', '"=>' ))
   cStr  := (StrTran( cStr, '""', '"' ))
   cStr  := (StrTran( cStr, ',"is_bot"=>false,', ',' ))
   cStr  := (StrTran( cStr, 'false', '.f.' ))
   hHash := &cStr
   aHash := HGetValueAt( hHash, 1 )
return aHash

where is the error ?


give me this error

Code: Select all

Application
===========
   Path and name: C:\Work\Errori\hash\test.Exe (32 bits)
   Size: 3,606,016 bytes
   Compiler version: Harbour 3.2.0dev (r1703231115)
   FiveWin  version: FWH 17.12
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.2, Build 9200 

   Time from start: 0 hours 0 mins 0 secs 
   Error occurred at: 09/21/18, 23:30:52
   Error description: Error BASE/1003  Variable does not exist: TRUE

Stack Calls
===========
   Called from: test.prg => STRTOHASHARRAY( 67 )
   Called from: test.prg => TEST( 50 )
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: hash

Post by anserkk »

Did you try
hb_jsonDecode( <jsonString>, @var, [<codePage>] ) -> length of decoded <jsonString>, var will contain the resulting Harbour value
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: hash

Post by Silvio.Falconi »

Enrico yes I saw but I have another error on hash
I try to save some data info from hash and sometimes make error because there may not be that informations I wish


and make error

Code: Select all

 Error occurred at: 22-09-2018, 11:05:43
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = H   {=>}
     [   2] = C   last_name
please see this picture

Image

when I save the hash data I made
for each x in Hdata
....
first_name:=x["message"]["from"]["first_name"]
last_name :=x["message"]["from"]["last_name"]
username :=x["message"]["from"]["username"]

but I have only first_name and user_name

but last_name now there is not but it but it could be there

How I can to you the expression

IIF(! empty( ) , x["message"]["from"]["last_name"],)

what I insert on empty function ?

How I can control if there is a variable on hash data ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: hash

Post by Silvio.Falconi »

FOUND

IF HHasKey( HaDATA, "lAST_NAME" )
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply