hash

hash

Postby Silvio.Falconi » Fri Sep 21, 2018 9:34 pm

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

Code: Select all  Expand view  RUN
#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  Expand view  RUN
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 )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: hash

Postby anserkk » Sat Sep 22, 2018 5:00 am

Did you try
hb_jsonDecode( <jsonString>, @var, [<codePage>] ) -> length of decoded <jsonString>, var will contain the resulting Harbour value
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: hash

Postby Enrico Maria Giordano » Sat Sep 22, 2018 8:25 am

Add

Code: Select all  Expand view  RUN
cStr  := (StrTran( cStr, 'true', '.t.' ))


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8719
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: hash

Postby Silvio.Falconi » Sat Sep 22, 2018 9:05 am

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  Expand view  RUN
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 ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: hash

Postby Silvio.Falconi » Sat Sep 22, 2018 9:14 am

FOUND

IF HHasKey( HaDATA, "lAST_NAME" )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests