Happy New Year Everyone!
I see lots of information about JSON. I was wondering if there was function or sample code that can read JSON response and store to an array?
Thank you!
Function MyJson( cStr )
local hHash
local nLen
nLen := hb_JsonDecode( cStr, @hHash )
if !Empty( nLen )
XBrowser hHash Setup ( oBrw:AutoFit() )
endif
Return nil
proc testJSON(cStr)
LOCAL r := hb_jsonDecode(cStr)
? cStr, "-->", r, "("+valtype(r)+")"
proc main()
testJSON('undefined')
testJSON('true')
testJSON('54')
testJSON('"aa"')
testJSON('{"a":4}')
testJSON('[1,2,3]')
undefined --> NIL (U)
true --> .T. (L)
54 --> 54 (N)
"aa" --> aa (C)
{"a":4} --> (H)
[1,2,3] --> (A)
aInfo := { }
cJson :='{"vin":"' + cVin + '"}'
oHttp:Send(cJson)
cRet := ""
cRtext := oHttp:responseText
nLen := hb_jsondecode( cRtext, @cRet )
AADD( aInfo, "LAST REPORTED SERVICES:")
FOR EACH o IN cRet["serviceHistory"]["serviceCategories"]
SC1 := o["serviceName"]
SC2 := o["dateOfLastService"]
nRetItm := 0
IF HHasKey( o, "odometerOfLastService" )
nRetItm := o["odometerOfLastService"]
ENDIF
SC3 := STR( nRetItm ) //HB_HGETDEF( o, "odometerOfLastService", 0 ),8)
aadd( aInfo, "> " + SC1 + " performed on " + SC2 + " Odometer: " + SC3 )
NEXT
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 89 guests