获取类别JSON中的JSON对象

时间:2014-07-03 13:44:27

标签: php json

{
 meta: {}
 notifications: []
 response: {}
}

FULL JSON = https://api.foursquare.com/v2/venues/4c6397fbec94a5937d472cca/tips?sort=recent&oauth_token=QABX2VQDBCHYJOHYQUGMNMBBA3KZY41YOOVNT5MY1OFYFYNA&v=20140703

$asObjects = json_decode($json);

foreach ($asObjects as $obj) 
{
    echo $obj->response->text;
    echo "<br>";
}

此方法不起作用,因为response : {}中的文字如何获取文字?

1 个答案:

答案 0 :(得分:2)

看到完整的json后,你需要迭代items数组,然后显示每个项目的文本:

$jsonObj = json_decode($json);

foreach ($jsonObj->response->tips->items as $obj) 
{
    echo $obj->text;
    echo "<br>";
}