Skip to content
Advertisement

Parsing nested json data to extract a certain value

so I have a nested JSON response form a JSON request I’m having trouble parsing the nested JSON data to get a certain value I have commented out on the data in need ( “link”: “http://i.imgur.com/DnjD527h.gif”) need to extract data in two places see the JSON data for comments. Since I don’t have a good understanding of array need some help figuring out the issue. thank you

Complete JSON data

JavaScript

Currently this what im trying

JavaScript

but getting this error . Notice: Trying to get property ‘link’ of non-object in C:xampphtdocstesttest.php on line 29 Any help would be much appreciated

Advertisement

Answer

Better work with objects than arrays:

JavaScript

Then use the following loop:

JavaScript

Some objects have no “images” property, that’s why you get the error. It’s eliminated by the isset function.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement