Echo特定元素JSON到Array

时间:2018-06-13 21:22:08

标签: php arrays json

您好,我试图回应以下JSON中的特定元素。

我首先尝试使用以下内容打印所有内容并且有效。

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

但我想要的是用他的名字和球衣号打印每个球员。

teams->主页 - > players->名称 - >用名字

teams->主页 - > players->名称 - >姓

teams->主页 - > players->衬衫

我尝试了不同的东西,但每次收到如下错误

注意:尝试获取非对象的属性

{
  "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"
        }
    ]
    }
  }
}

如果有人帮助我,我将不胜感激。

由于

0 个答案:

没有答案