0

Hi I'm trying to echo specific elements from the following JSON.

I've tried first to print everything with the following and it works.

$obj1 = json_decode($str, true);
echo $str;

But what I want is to print each player with his name and shirt number.

teams->home->players->name->forename

teams->home->players->name->surname

teams->home->players->shirt

I've tried different things but every time I get an error like the following

Notice: Trying to get property of non-object

{
  "teams": {
    "home": {
      "id": "528",
      "formation": "4212",
      "players": [
        {
          "id": "8576",
          "name": {
            "surname": "Isco"
          },
          "shirt": "22"
        },
        {
          "id": "5886",
          "name": {
            "initial": "K",
            "forename": "Karim",
            "surname": "Benzema"
          },
          "shirt": "9"
        },
        {
          "id": "136",
          "name": {
            "initial": "C",
            "forename": "Cristiano",
            "surname": "Ronaldo"
          },
          "shirt": "7"
        }
      ],
      "subs": [
                {
          "id": "188",
          "name": {
            "initial": "N",
            "forename": "Nathaniel",
            "surname": "Clyne"
          },
          "shirt": "2"
        }
    ]
    }
  }
}

I will appreciate it if anyone helps me with this.

Thanks

0 Answers0