parsing json

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

parsing json

Post by paulalsmith1000 » Thu Jan 02, 2020 8:32 pm

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

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: parsing json

Post by Klaus » Thu Jan 02, 2020 8:46 pm

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

paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

Re: parsing json

Post by paulalsmith1000 » Fri Jan 03, 2020 7:35 am

Hi Klaus

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

Kind regards

Paul

Post Reply

Return to “Internet”