1

I have the following JSON structure

{"Id":"1","Persons":[{"Name":"Carl","Time":"00:00:03","info":"","Timeext":"","Timeout":"","Timein":""}, {"Name":"Carl","Time":"00:00:03","info":"","Timeext":"","Timeout":"","Timein":""}{"Name":"Luis","Time":"00:00:08","info":"","Timeext":"","Timeout":"","Timein":""}]}

How I can have acces or read the item inside the nest? For example if I just want the value of time for Carl or all information about Carl. Till now I just can get without a problem the single item in the collection 'Id'. The rst nested items not. I tryed with json_decode like this:

if( $_POST ) {

            $arr['Id'] = $_POST['Id'];
            $arr['NP'] = $_POST['NP'];

            $jsdecode = json_decode($arr);

            foreach ($jsdecode as $values){
                echo $values->Time;
            }

Can PLEASE somebody help me?

2
  • use var_dump or print_r and check the array elements with their values Commented Oct 21, 2015 at 11:32
  • Is the JSON sent as the full body of the request, or is it url-encoded? Commented Oct 21, 2015 at 11:37

2 Answers 2

5
if( $_POST ) {

        $arr['Id'] = $_POST['Id'];
        $arr['NP'] = $_POST['NP'];

        $jsdecode = json_decode($arr,true);

        foreach ($jsdecode as $values){
            echo $values->Time;
        }

Adding 'true' to json_decode converts it to array

Sign up to request clarification or add additional context in comments.

2 Comments

Hi! Thanks for your answer! I tried like you said but I don't get the correct result. But at least the jqury answer me undefined, before was nothing :)
Like this I am doing in the client side: success: function (data) { $(data).each(function(i, v){ alert( v.Time); }) },
1

You are processing it correct , Just add true as the second parameter to json_decode which will be converted to an Array like

$jsdecode = json_decode($arr,true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.