PHP foreach循环使用JSON数据 [英] PHP foreach loop with JSON Data
本文介绍了PHP foreach循环使用JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 BandsInTown API ,我试图列出所有事件的标题为乐队。下面的code工作的第一个冠军,但我需要通过所有的人看。我尝试了foreach循环,我发现放在这里,但没有任何运气。我如何显示所有特定波段赛的冠军?我一直在寻找previous问题像这样的。
$ JSON = file_get_contents(\"http://api.bandsintown.com/artists/Skrillex/events.json?api_version=2.0&app_id=MYID\");
$数据= json_de code($ JSON);
回声$数据[0] - >称号;//我想这一点,但它没有工作
的foreach($数据 - >标题$标题){
回声$称号;
}
解决方案
我想你可能会寻找像
的foreach($的数据作为基准$){
回声$ datum->称号;
}
I am using the BandsInTown API, and I'm trying to list all the event titles for a band. The code below works for the first title, but I need to look through all of them. I tried a foreach loop I found on here, but did have any luck. How do I show all the event titles for a particular band? I have been looking at previous questions like this one.
$json = file_get_contents("http://api.bandsintown.com/artists/Skrillex/events.json?api_version=2.0&app_id=MYID");
$data = json_decode($json);
echo $data[0]->title;
// I tried this, but it didn't work
foreach($data->title as $title){
echo $title;
}
解决方案
I think you might be look for something like
foreach($data as $datum){
echo $datum->title;
}
这篇关于PHP foreach循环使用JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文