我正在尝试解析 Twitch 用户玩某个游戏的请求。结果如下所示:
{
"data":
[{
"id":"id here",
"user_id":"uid here",
"user_name":"name here",
"game_id":"gameid here",
"community_ids":[IDs here],
"type":"live",
"title":"awesome title here",
"viewer_count":10,000,000,
"started_at":"time here",
"language":"en",
"thumbnail_url":"url here",
"tag_ids":[look at all these tags!]
},{
"id":"id here",
"user_id":"uid here",
"user_name":"name here",
"game_id":"gameid here",
"community_ids":[IDs here],
"type":"live",
"title":"awesome title here",
"viewer_count":10,000,000,
"started_at":"time here",
"language":"en",
"thumbnail_url":"url here",
"tag_ids":[look at all these tags!]
etc. etc.
}],
"pagination":{"cursor":"whatever this does"}
}
我试图通过以下方式解析它:
$results = json_decode($query, TRUE);
foreach($results as $data){
foreach($data as $users){
echo ($users['user_name']."<br/>");
}
}
我得到的结果如下所示:
name 1
...
name n
Warning: Illegal string offset 'user_name'
*first letter of pagination thing here (in this example it would be the 'w' in 'whatever')*
理想情况下,我希望这个返回:
user_Name, viewer_count, language,title
但是我卡在第一步...