首页 > 解决方案 > JSON对象循环

问题描述

如果存在,如何获取 instagram_business_id (id)?启用获取它,未定义索引 instagram_business_id 错误

    $pages = '[
  {
    "access_token": "",
    "instagram_business_account": {
      "id": "123"
    },
    "name": "Page Name",
    "id": "XXX"
  },
  {
    "access_token": "",
    "name": "Page Name2",
    "id": "XXX"
  }
]';

Loop
foreach($pages as $page){

}

标签: phpjson

解决方案


检查下面的代码 $res = json_decode($pages, true);

print_r($res[0]['instagram_business_account']);


推荐阅读