How to read a hash from a file

Post Reply
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

How to read a hash from a file

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to read a hash from a file

Post by cnavarro »

It's not enough with

Code: Select all

hb_JsonDecode( MemoRead( cFile ), @h ) 
 
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: How to read a hash from a file

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to read a hash from a file

Post 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?
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: How to read a hash from a file

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to read a hash from a file

Post 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 )
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply