When I check the JSONType() after parsing the data below with ParseJson() I find that the JSON type is array which makes sense. However, I cannot find a method to extract the JSON objects from this array. ExportJSONArray() does not work because you cannot define an array of type JsonObject and neither string or integer works.
I can use StringField() to get each string and then use ParseJSON() on each string to get a JSONObject(). However is there a method to extract this data without using Stringfield()? I would assume that it should all be able to be done with JSON functions.
Code: Select all
lcJSON=~"[{\"date\":\"20201103\",\"exchtous\":0.73456,\"price\":1.111,\"pricecd\":1.112,\"pricefs\":1.115,\"product\":\"clrdsl\",\"time\":\"00:00\"},"+
~"{\"date\":\"20201103\",\"exchtous\":0.73456,\"price\":2.111,\"pricecd\":2.112,\"pricefs\":2.115,\"product\":\"reggas\",\"time\":\"00:00\"},"+
~"{\"date\":\"20201103\",\"exchtous\":0.73456,\"price\":3.111,\"pricecd\":3.112,\"pricefs\":3.115,\"product\":\"dyedsl\",\"time\":\"00:00\"}]"
lcJSON = RemoveString(RemoveString(lcJSON,"["),"]")
lnCnt = CountString(lcJSON,"}")
For ln = 1 To lnCnt
lcTxt.s = StringField(lcJSON,ln,"}")+"}"
If Left(lcTxt,1)=","
lcTxt = Mid(lcTxt,2)
EndIf
Debug lcTxt
loJSON = ParseJSON(#PB_Any,lcTxt)
Debug JSONErrorMessage()
lnJVal =JSONValue(loJSON)
If ExamineJSONMembers(lnJVal)
While NextJSONMember(lnJVal)
lnVal.i = JSONMemberValue(lnJVal)
Select JSONType(lnVal)
Case #PB_JSON_Null: Debug JSONMemberKey(lnJVal)+" null"
Case #PB_JSON_String: Debug JSONMemberKey(lnJVal)+" "+GetJSONString(lnVal)
Case #PB_JSON_Number: Debug JSONMemberKey(lnJVal)+" "+StrD(GetJSONDouble(lnVal))
Case #PB_JSON_Boolean: Debug JSONMemberKey(lnJVal)+" "+Str(GetJSONBoolean(lnVal))
Case #PB_JSON_Array: Debug JSONMemberKey(lnJVal)+" array"
Case #PB_JSON_Object: Debug JSONMemberKey(lnJVal)+" object"
EndSelect
Wend
EndIf
Next