How to read a hash from a file

How to read a hash from a file

Postby Otto » Sun May 17, 2020 5: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to read a hash from a file

Postby cnavarro » Sun May 17, 2020 6:20 pm

It's not enough with
Code: Select all  Expand view  RUN

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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to read a hash from a file

Postby Otto » 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to read a hash from a file

Postby cnavarro » 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: Select all  Expand view  RUN

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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to read a hash from a file

Postby Otto » Sun May 17, 2020 11:40 pm

Dear Cristobal,
Thank you.
Now it is working fine.
In mod harbour I write

Code: Select all  Expand view  RUN
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to read a hash from a file

Postby nageswaragunupudi » Mon May 18, 2020 5: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: Select all  Expand view  RUN

hHash := &( MEMOREAD( <cfile> ) )
 

-----------------------------
Then if you want you can test the hash with
Code: Select all  Expand view  RUN

XBROWSER hHash
 


If you want to convert the hash to Json
Code: Select all  Expand view  RUN

cJson := HB_JsonEncode( hHash )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10659
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 62 guests