1

This is the data I work with:

{
    "jornadas": [
        {
            "partits": [
                {
                    "local": 1,
                    "visitante": 2
                },
                {
                    "local": 3,
                    "visitante": 4
                },
                {
                    "local": 5,
                    "visitante": 6
                }
            ]
        },
        {
            "partits": [
                {
                    "local": 1,
                    "visitante": 2
                },
                {
                    "local": 3,
                    "visitante": 4
                },
                {
                    "local": 5,
                    "visitante": 6
                }
            ]
        },
        {
            "partits": [
                {
                    "local": 1,
                    "visitante": 2
                },
                {
                    "local": 3,
                    "visitante": 4
                },
                {
                    "local": 5,
                    "visitante": 6
                }
            ]
        },
        {
            "partits": [
                {
                    "local": 1,
                    "visitante": 2
                },
                {
                    "local": 3,
                    "visitante": 4
                },
                {
                    "local": 5,
                    "visitante": 6
                }
            ]
        },
        {
            "partits": [
                {
                    "local": 1,
                    "visitante": 2
                },
                {
                    "local": 3,
                    "visitante": 4
                },
                {
                    "local": 5,
                    "visitante": 6
                }
            ]
        }
    ]
}

And when it goes to php, I decode it and the print_f result is:

stdClass Object ( [jornadas] => Array ( [0] => stdClass Object ( [partits] => Array ( [0] => stdClass Object ( [local] => 2 [visitante] => 7 ) [1] => stdClass Object ( [local] => 3 [visitante] => 5 ) [2] => stdClass Object ( [local] => 4 [visitante] => 1 ) ) ) [1] => stdClass Object ( [partits] => Array ( [0] => stdClass Object ( [local] => 1 [visitante] => 7 ) [1] => stdClass Object ( [local] => 5 [visitante] => 4 ) [2] => stdClass Object ( [local] => 2 [visitante] => 3 ) ) ) [2] => stdClass Object ( [partits] => Array ( [0] => stdClass Object ( [local] => 3 [visitante] => 7 ) [1] => stdClass Object ( [local] => 4 [visitante] => 2 ) [2] => stdClass Object ( [local] => 1 [visitante] => 5 ) ) ) [3] => stdClass Object ( [partits] => Array ( [0] => stdClass Object ( [local] => 5 [visitante] => 7 ) [1] => stdClass Object ( [local] => 2 [visitante] => 1 ) [2] => stdClass Object ( [local] => 3 [visitante] => 4 ) ) ) [4] => stdClass Object ( [partits] => Array ( [0] => stdClass Object ( [local] => 4 [visitante] => 7 ) [1] => stdClass Object ( [local] => 1 [visitante] => 3 ) [2] => stdClass Object ( [local] => 5 [visitante] => 2 ) ) ) ) )

Well I'm overwhelmed, because I cannot retreive any data from this json. If you give me any advise, I'll be very grateful

1
  • 1
    it is a object. if you want it as an array then convert it. Commented Jul 29, 2014 at 9:48

2 Answers 2

6

This answer assumes you are using the json_decode function of PHP.

You should decode it with the 2nd parameter as true:

json_decode($yourJSON, true);

This gives you an associative array instead of an stdClass object.

More information on the json_decode function: http://php.net/manual/en/function.json-decode.php

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

2 Comments

Did you read that when it goes to php, I decode it and the print_f result is:?
I did and I assume he decodes it with json_decode, and if he did, he didn't set the 2nd parameter to true.
1

try foreach after decode

$decode = json_decode($json, true); //decodes in associative array
foreach($decode['jornadas'] as $k=>$v) {
  foreach($v['partits'] as $k1=>$v1) {
     echo $v1['local'];
     echo $v1['visitante'];
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.