dongxing4805 2013-04-27 09:36
浏览 59
已采纳

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 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;
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证