0

I have an objet JSON which is like this :

{"type":"champion","version":"5.22.3","data":
    {"Thresh":{
        "id":412,
        "key":"Thresh",
        "name":"Thresh",
        "title":"the Chain Warden",
        "image":{
            "full":"Thresh.png",
            "sprite":"champion3.png",
            "group":"champion",
            "x":336,
            "y":0,
            "w":48,
            "h":48
        }}

When I parse with this command :

$json = file_get_contents($Api_PATH);
$obj = json_decode($json);

I get all the datas but if i need to get only the datas in the image object, how can I do?

This is the vardump($obj) :

object(stdClass)#366 (3) 
{ 
    ["type"]=> string(8) "champion" 
    ["version"]=> string(6) "5.22.3" 
    ["data"]=> object(stdClass)#365 (127) { ["Thresh"]=> object(stdClass)#369 (5) { 
            ["id"]=> int(412) 
            ["key"]=> string(6) "Thresh" 
            ["name"]=> string(6) "Thresh" 
            ["title"]=> string(16) "the Chain Warden" 
            ["image"]=> object(stdClass)#368 (7) { 
                ["full"]=> string(10) "Thresh.png" 
                ["sprite"]=> string(13) "champion3.png" 
                ["group"]=> string(8) "champion" 
                ["x"]=> int(336) 
                ["y"]=> int(0) 
                ["w"]=> int(48) 
                ["h"]=> int(48) 
} }

I already tried: $obj->data->image --> Not working... (Undefined property: stdClass::$image)

I tried to foreach the 2 objects but any results...

foreach ($obj->data->image as $value) {
   Error
}
Matthieu
  • 225
  • 1
  • 3
  • 16
  • 2
    `["Thresh"]=> object(stdClass)#369 (5) {` See that on the same line as `["data"]=> object(stdClass)#365 (127) {` So your object is even more nested. – Rizier123 Nov 23 '15 at 12:26
  • It didnt work when I foreach. It's not a duplicate question, because it didn't solve ny problem. – Matthieu Nov 23 '15 at 12:49
  • You do the exact same mistake. Read the dupe carefully how to read the output from `var_dump()` and how to access a single property from it. – Rizier123 Nov 23 '15 at 12:53

0 Answers0