Page 1 of 1

How to read a hash from a file

Posted: Sun May 17, 2020 5:53 pm
by Otto
Hallo,
is there a function to read such a hash:

{"UUID"=>"value", "anrede1"=>"frau", "anrede2"=>"", "gender"=>"", "titel"=>"DI", "staat"=>"Indien", "Passnummer"=>"1234", "EmailCheck"=>"Anmelden", "Vorname1"=>"V1", "Nachname1"=>"N1", "GebDatum1"=>"2020-05-12", "Vorname2"=>"V2", "Nachname2"=>"N2", "GebDatum2"=>"2020-05-05", "Vorname3"=>"V3", "Nachname3"=>"N3", "GebDatum3"=>"2020-04-27", "Vorname4"=>"V4", "Nachname4"=>"N4", "GebDatum4"=>"2020-05-04", "Vorname5"=>"V5", "Nachname5"=>"N5", "GebDatum5"=>"2020-05-05", "Email"=>"iris%40atzwanger.com", "herkunft"=>"Italien", "anreise"=>"2020-05-11", "abreise"=>"12052020"}

Thank you in advance
Otto

Re: How to read a hash from a file

Posted: Sun May 17, 2020 6:20 pm
by cnavarro
It's not enough with

Code: Select all

hb_JsonDecode( MemoRead( cFile ), @h ) 
 

Re: How to read a hash from a file

Posted: Sun May 17, 2020 10:06 pm
by Otto
Dear Cristobal,
this is working for me only if the hash is like this
{"selected":["117","119","110","111","112","113","101"], "res":{"rooms":["101"]} }

So I will format => to : and insert [] with strtran-function.
Best regards
Otto

Re: How to read a hash from a file

Posted: Sun May 17, 2020 10:55 pm
by cnavarro
Otto wrote:Dear Cristobal,
this is working for me only if the hash is like this
{"selected":["117","119","110","111","112","113","101"], "res":{"rooms":["101"]} }

So I will format => to : and insert [] with strtran-function.
Best regards
Otto
Dear Otto, try with

Code: Select all

hb_JsonDecode( StrTran( MemoRead( cFile ), "=>", ":" ), @h )
 
how do you know where the array will start?

Re: How to read a hash from a file

Posted: Sun May 17, 2020 11:40 pm
by Otto
Dear Cristobal,
Thank you.
Now it is working fine.
In mod harbour I write

Code: Select all

function Main()
   local hPairs := AP_PostPairs()
   local cLog
   cLog := hb_jsonEncode( ValToChar( hPairs ) ) 
   cSaveTXT := cNewFileName( AP_GETENV( 'DOCUMENT_ROOT' ) + "/meldemax/meldeblatt", "txt" ) 
   MEMOWRIT( cSaveTXT , cLog, .f. ) 
 
Then I download the file with FTP.

Best regards,
Otto

Re: How to read a hash from a file

Posted: Mon May 18, 2020 5:49 pm
by nageswaragunupudi
Otto wrote:Hallo,
is there a function to read such a hash:

{"UUID"=>"value", "anrede1"=>"frau", "anrede2"=>"", "gender"=>"", "titel"=>"DI", "staat"=>"Indien", "Passnummer"=>"1234", "EmailCheck"=>"Anmelden", "Vorname1"=>"V1", "Nachname1"=>"N1", "GebDatum1"=>"2020-05-12", "Vorname2"=>"V2", "Nachname2"=>"N2", "GebDatum2"=>"2020-05-05", "Vorname3"=>"V3", "Nachname3"=>"N3", "GebDatum3"=>"2020-04-27", "Vorname4"=>"V4", "Nachname4"=>"N4", "GebDatum4"=>"2020-05-04", "Vorname5"=>"V5", "Nachname5"=>"N5", "GebDatum5"=>"2020-05-05", "Email"=>"iris%40atzwanger.com", "herkunft"=>"Italien", "anreise"=>"2020-05-11", "abreise"=>"12052020"}

Thank you in advance
Otto

Code: Select all

hHash := &( MEMOREAD( <cfile> ) )
 
-----------------------------
Then if you want you can test the hash with

Code: Select all

XBROWSER hHash
 
If you want to convert the hash to Json

Code: Select all

cJson := HB_JsonEncode( hHash )