Page 1 of 1

parsing json

Posted: Thu Jan 02, 2020 8:32 pm
by paulalsmith1000
Evening Livecoders

I wonder if anyone could help me with the following:-

I've previously had some success importing the json response from something and then extracting the info I wanted. However, this time, to many hours has got me nowhere, so here I am again.

The request is a variation on this- https://maps.googleapis.com/maps/api/di ... dVjYr8a9Ew

All I want to do extract the distance values for each location i.e. 24m / 0.7km, but apart from the addresses everything comes back blank.

It seems to be laid out differently to last time? before so I think I must be using the wrong keys or something.

As ever any help much appreciated.

Kind regards

Paul

Re: parsing json

Posted: Thu Jan 02, 2020 8:46 pm
by Klaus
Hi Paul,

you could load the url and then convert it to an LC array with:

Code: Select all

...
put url("https://maps.googleapis.com/maps/api/distancematrix/json?origins=50.868376,0.251201...9Ew") into tMap
put jsontoarray(tMap) into tLCArray
... 
Then you can parse that array.
Hint:
To visualize the content of an array you can use a treeview-widget and set its "arraydata" to any array:

Code: Select all

...
put url("https://maps.googleapis.com/maps/api/distancematrix/json?origins=50.868376,0.251201...9Ew") into tMap
put jsontoarray(tMap) into tLCArray
set the arraydata of widget "you tree view widget here" to tLCArray
...
Great for understanding arrays, seeing is believing! :-)


Best

Klaus

Re: parsing json

Posted: Fri Jan 03, 2020 7:35 am
by paulalsmith1000
Hi Klaus

What can I say - perfect! thank you; 5 hours to 5 minutes.

Kind regards

Paul