0

下面是 json 数据,我想得到“平均值”的值。我能怎么做?

{

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 //附近共有多少个推荐潮地

}

我使用函数 json_decode 来解析下面的 json 数据。如何获得价值“平均”?

$jsonObj = json_decode($contentStr);
$items = $jsonObj->items;
4

1 回答 1

1

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;

?>
于 2013-04-27T09:47:47.077 回答