variable on json file

variable on json file

Postby Silvio.Falconi » Mon Mar 29, 2021 7:11 pm

I have a json file with some variables
{
"antonio": "888",
"silvio": "789",
"paul": "456",
"mary": "123"
}

If not found a variable there is not on json

::oConfig := hb_jsonDecode(MemoRead("config.json"))
lstatus := ::oConfig["status"]

the procedure make error because it not found the variable status

how do I tell the procedure that if status is a valid variable or not, that is, if it does not find it, it must set the .f value to lstatus. otherwise .t.

or existe a function type jsonlistkeys where I can see if exit that variable ?
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: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: variable on json file

Postby nageswaragunupudi » Mon Mar 29, 2021 7:28 pm

Code: Select all  Expand view

if HB_HHasKey( ::oConfig, "status" )
   ? ::oConfig[ "status" ]
else
   ? <your message>
endif
 
Regards

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

Re: variable on json file

Postby Silvio.Falconi » Mon Mar 29, 2021 7:41 pm

thanks Rao
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: 7053
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 39 guests