【发布时间】:2013-08-05 21:28:04
【问题描述】:
使用 Foursquare API,它会返回以下 JSON 提要
{"meta":{"code":200},"notifications":[{"type":"notificationTray","item":{"unreadCount":1}},{"type":"message ","item":{"message":"好的!我们有你@Place XXX。你来过这里两次。"}},{"type":"insights","item":{"见解":{"count":4,"items":[{"type":"pointsReward","image":"https://foursquare.com/img/points/discovery-venue3.png","title ":"你的朋友第一个签到地方 XXX!","shareable":false,"points":{"image":{"prefix":"https://foursquare.com/img/points/discovery-场地3_","sizes":[44,60,120],"name":".png"},"message":"你的朋友第一个入住地点 XXX!","points":5}},{" type":"pointsReward","image":"https://foursquare.com/img/points/discovery-venue3.png","title":"第一次在地方XXX。","shareable":false, "points":{"image":{"prefix":"https://foursquare.com/img/points/discovery-venue3_","sizes":[44,60,120],"name":".png" },"message":"第一次到地方 XXX。","points":5}},{"type":"pointsReward","image":"https://foursquare.com/img/points/category -outdoor.png","ti tle":"朋友第一广场签到!","shareable":false,"points":{"image":{"prefix":"https://foursquare.com/img/points/category- Outdoor_","sizes":[44,60,120],"name":".png"},"message":"First Plaza 签到你的朋友!","points":6}},{"type ":"pointsReward","image":"https://foursquare.com/img/points/discovery-venue3.png","title":"你的第一个朋友在这里签到。","shareable":错误,“点”:{“图像”:{“前缀”:“https://foursquare.com/img/points/discovery-venue3_”,“大小”:[44,60,120],“名称”:“。 png"},"message":"你的第一个朋友在这里签到。","points":2}}]}}},{"type":"leaderboard","item":{"total": 18,"scores":[{"icon":"https://foursquare.com/img/points/discovery-venue3.png","message":"你的朋友第一个签到... 我想做的是显示消息“好的!我们有你@Place XXX。你来过这里两次。”它嵌入在第二个“类型”标签中
我习惯于使用 foreach 函数来获得这种值,但使用这个我无法获得它。 我需要专家的帮助,感谢您的参与。
我尝试使用的代码没有成功:
$data = json_decode($response, true); // return array not object
foreach($data['notifications']['type'][0] as $item) {
echo $item['item']['message'];
}
【问题讨论】:
-
数据不是有效的 json。或者你错过了一些部分?
标签: php json foursquare