FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to read a hash from a file
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
How to read a hash from a file
Posted: Sun May 17, 2020 05:53 PM

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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to read a hash from a file
Posted: Sun May 17, 2020 06:20 PM
It's not enough with
Code (fw): Select all Collapse
hb_JsonDecode( MemoRead( cFile ), @h )
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to read a hash from a file
Posted: Sun May 17, 2020 10:06 PM

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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to read a hash from a file
Posted: Sun May 17, 2020 10:55 PM
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 (fw): Select all Collapse
hb_JsonDecode( StrTran( MemoRead( cFile ), "=>", ":" ), @h )


how do you know where the array will start?
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: How to read a hash from a file
Posted: Sun May 17, 2020 11:40 PM
Dear Cristobal,
Thank you.
Now it is working fine.
In mod harbour I write

Code (fw): Select all Collapse
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to read a hash from a file
Posted: Mon May 18, 2020 05:49 PM
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 (fw): Select all Collapse
hHash := &( MEMOREAD( <cfile> ) )

-----------------------------
Then if you want you can test the hash with
Code (fw): Select all Collapse
XBROWSER hHash


If you want to convert the hash to Json
Code (fw): Select all Collapse
cJson := HB_JsonEncode( hHash )
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion