Question

I am receiving a multilevel json like this:

{"id":"3",
"field2":"ssss",
"field3":[
         {"field31":"wwwww",
         "field32":"qqqq"},
         {"field31":"wwwww",
         "field32":"qqqq"},
         {"field31":"wwwww",
         "field32":"qqqq"},
   ]}    

I am reading json values (first level) like this in php:

$json = file_get_contents('php://input');
$json_post = json_decode(utf8_decode($json), true);
$id = $json_post['id'];

But I don't know how to get the json in the second level. What is the simplest way? I just need to get the json in other variable like $json_post, I will read it in a for bucle to get each row of the json file

Était-ce utile?

La solution

It's going to give you a PHP object if you run json_decode(utf8_decode($json));

echo $json_post->field3->field31;

EDIT: I missed that you were using the conversion to array. This is what the array would look like

    echo $json_post['field3']['field31'];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top