dongxing4805
dongxing4805
2013-04-27 09:36
浏览 52

php json decode,如何获得这个值?

Below is json data, I want to get the value 'average'. How can I do?

{

items: [
{

city: "北京",
tel: "85306308-1004",
name: "巴西之家",
mayor_id: 877861620, //当前地主的用户id
venue_info:
{
//地点的评分信息
rating: 7.6, //地点平均分,10分为满分
**average: 116** //地点人均消费(单位:人民币)

},
lon: 116.437031906407,
checkin_users_num: 133, //地点总签到用户数
lat: 39.9131007742324,
checkin_num: 161, //地点总签到数
addr: "朝阳区光华路44号(巴西大使馆对面)",
dist: "200 m", //地点距离传入坐标相对距离
guid: "774E9ED4B79AF2A9904ECDA2F8D70565", //地点的id
description: "地道巴西美食,从芝士夹心面包就征服食客", //推荐潮地的推荐语
img: "http://img.jiepang.com/get/photo/182a6154e2dedbdf111bf29347ad6aa7?size=120" //推荐潮地配图

},
{
},
{
},
],
num_items: 44 //附近共有多少个推荐潮地

}

I use the function json_decode to parse below json data. How to get the value 'average'?

$jsonObj = json_decode($contentStr);
$items = $jsonObj->items;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtds8802
    dtds8802 2013-04-27 09:47
    已采纳

    Had to reformat some stuff, not sure if it was invalid JSON or just the foreign characters, but this should work:

    <?
              $js = '{ "items" : [{"city": "a",
                 "tel": "85306308-1004",
                 "name": "b",
                 "mayor_id": 877861620,
                 "venue_info": {"rating": 7.6,
                              "average": 116
                             },
                 "lon": 116.437031906407,
                 "checkin_users_num": 133,
                 "lat": 39.9131007742324,
                 "checkin_num": 161,
                 "addr": "b",
                 "dist": "200 m",
                 "guid": "774E9ED4B79AF2A9904ECDA2F8D70565",
                 "description": "c",
                 "img": "http://img.jiepang.com/get/photo/182a6154e2dedbdf111bf29347ad6aa7?size=120"
                },
                {},
                {}],
        "num_items": 44}';
    
        $o = json_decode($js);
    
        $average = $o->items[0]->venue_info->average;
    
    ?>
    
    点赞 评论

相关推荐