I use my interpreter which read the file, then expand to UTF16LE then declare a JsonObject (from JsonObject.cls), and then I do some magic: We can get a JsonArray from then ItemPath. This Array has 8 items, but item 0 has the length of array (.?|.?), We can use itempath from that object and read anything.
So you need two classes https://github.com/M2000Interpreter/...JsonObject.cls
and https://github.com/M2000Interpreter/.../JsonArray.cls
And follow the methods/functions from the script.
The idea is: Use the ItemPath.
Code:
A=buffer("json1.txt")
Locale 1033
Document a$=chr$(A[0, Len(A)])
//clipboard a$
declare Json JsonObject
Json=Json=>parser(a$)^
clipboard Json=>Json(4)
M=Json=>ItemPath("results.0.address_components")^
Print Val(M=>ItemPath("0.long_name"))' 7 = M=>count-1
For i=1 to M=>count-1
Print i," Long name ";M=>ItemPath(i+".long_name")
Print "","Short name "; M=>ItemPath(i+".short_name")
next
Print Json=>ItemPath("status")'"OK"
I use my interpreter which read the file, then expand to UTF16LE then declare a JsonObject (from JsonObject.cls), and then I do some magic: We can get a JsonArray from then ItemPath. This Array has 8 items, but item 0 has the length of array (.?|.?), We can use itempath from that object and read anything.
So you need two classes https://github.com/M2000Interpreter/...JsonObject.cls
and https://github.com/M2000Interpreter/.../JsonArray.cls
And follow the methods/functions from the script.
The idea is: Use the ItemPath.
Code:
A=buffer("json1.txt")
Locale 1033
Document a$=chr$(A[0, Len(A)])
//clipboard a$
declare Json JsonObject
Json=Json=>parser(a$)^
clipboard Json=>Json(4)
M=Json=>ItemPath("results.0.address_components")^
Print Val(M=>ItemPath("0.long_name"))' 7 = M=>count-1
For i=1 to M=>count-1
Print i," Long name ";M=>ItemPath(i+".long_name")
Print "","Short name "; M=>ItemPath(i+".short_name")
next
Print Json=>ItemPath("status")'"OK"
Not complete undersatand this code:
Code:
A=buffer("json1.txt")
Locale 1033
Document a$=chr$(A[0, Len(A)])
//clipboard a$
declare Json JsonObject
Json=Json=>parser(a$)^
clipboard Json=>Json(4)
M=Json=>ItemPath("results.0.address_components")^
Print Val(M=>ItemPath("0.long_name"))' 7 = M=>count-1
For i=1 to M=>count-1
Print i," Long name ";M=>ItemPath(i+".long_name")
Print "","Short name "; M=>ItemPath(i+".short_name")
next
Print Json=>ItemPath("status")'"OK"
Last edited by dday9; Today at 11:49 AM.
Reason: Added code tags