This is the formated text from the script bellow. (using 0 parameter we get the json without white space/newlines)
Code:
{
"results" : [
{
"address_components" : [
{
"long_name" : "7",
"short_name" : "7",
"types" : [
"street_number"
]
},
{
"long_name" : "Via Toledo",
"short_name" : "Via Toledo",
"types" : [
"route"
]
},
{
"long_name" : "Napoli",
"short_name" : "Napoli",
"types" : [
"locality",
"political"
]
},
{
"long_name" : "Napoli",
"short_name" : "Napoli",
"types" : [
"administrative_area_level_3",
"political"
]
},
{
"long_name" : "Città Metropolitana di Napoli",
"short_name" : "NA",
"types" : [
"administrative_area_level_2",
"political"
]
},
{
"long_name" : "Campania",
"short_name" : "Campania",
"types" : [
"administrative_area_level_1",
"political"
]
},
{
"long_name" : "Italia",
"short_name" : "IT",
"types" : [
"country",
"political"
]
},
{
"long_name" : "80134",
"short_name" : "80134",
"types" : [
"postal_code"
]
}
],
"formatted_address" : "Via Toledo, 7, 80134 Napoli NA, Italia",
"geometry" : {
"location" : {
"lat" : 40.84798,
"lng" : 14.2496255
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 40.8493328802915,
"lng" : 14.2509291302915
},
"southwest" : {
"lat" : 40.8466349197085,
"lng" : 14.2482311697085
}
}
},
"navigation_points" : [
{
"location" : {
"latitude" : 40.8479807,
"longitude" : 14.2496175
}
}
],
"place_id" : "ChIJeZ7gn1wIOxMR6fvfZkrDK4E",
"types" : [
"street_address",
"subpremise"
]
}
],
"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"