E
E
Eugene2016-02-09 23:33:08
PHP
Eugene, 2016-02-09 23:33:08

How to parse complex json in php?

Essence of the question:
We have a complex JSON of the form:

{
 "Count":20,
 "results": [
{"id":"1372", "idCat":"2", "Dev":"http://mysite.com", 
"screenshot":["Link1", "Link2", "Link3"], "Url":"http://myappsite.com"},
{"id":"342", "idCat":"4", "Dev":"http://mysite2.com", 
"screenshot":["Link1", "Link2", "Link3"], "Url":"http://myappsite2.com"},
{"id":"433", "idCat":"5", "Dev":"http://mysite3.com", 
"screenshot":["Link1", "Link2", "Link3"], "Url":"http://myappsite3.com"}
]}

How to parse all attachments? It is possible to receive only Count. The rest doesn't work.
$j = file_get_contents($url_json_parse);
      $data = json_decode($j);
      
      print $data-> Count;

Gives a normal result of 20.
And if you write such a print:
print $data->results->id[0];
Swears: Notice: Trying to get property of non-object

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2016-02-09
@xmax

$data->results[0]->id
In general, pass the second parameter true to json_decode() - it's easier to work with arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question