weixin_41509536
weixin_41509536
采纳率100%
2021-02-27 23:36

PHP Json取数据

已采纳
{
    "error": false,
    "response": {
        "offline": false,
        "server": {
            "id": 2,
            "name": "Simulation 1",
            "short": "EU SIM 1",
            "game": "ets2",
            "url": "sim1",
            "percent": 70,
            "color": "#66bb6a",
            "order": 1
        },
        "top": [
            {
                "id": 134,
                "name": "Calais - Duisburg (Road)",
                "country": "Germany",
                "severity": "Congested",
                "players": 251
            },
            {
                "id": 14,
                "name": "Duisburg (City)",
                "country": "Germany",
                "severity": "Congested",
                "players": 101
            },
            {
                "id": 55,
                "name": "Calais (City)",
                "country": "France",
                "severity": "Congested",
                "players": 82
            },
            {
                "id": 141,
                "name": "Calais - Duisburg (Intersection)",
                "country": "Germany",
                "severity": "Heavy",
                "players": 39
            },
            {
                "id": 60,
                "name": "Paris (City)",
                "country": "France",
                "severity": "Low",
                "players": 39
            },
            {
                "id": 57,
                "name": "Lille (City)",
                "country": "France",
                "severity": "Heavy",
                "players": 37
            },
            {
                "id": 42,
                "name": "Amsterdam (City)",
                "country": "Netherlands",
                "severity": "Heavy",
                "players": 36
            },
            {
                "id": 217,
                "name": "Calais (Intersection)",
                "country": "France",
                "severity": "Moderate",
                "players": 35
            }
        ]
    }
}

如何取到"name": "Calais - Duisburg (Road)",

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • wanmeikakaxi wanmeikakaxi 2月前
    <?php
        $json = '{"error":false,"response":{"offline":false,"server":{"id":2,"name":"Simulation 1","short":"EU SIM 1","game":"ets2","url":"sim1","percent":70,"color":"#66bb6a","order":1},"top":[{"id":134,"name":"Calais - Duisburg (Road)","country":"Germany","severity":"Congested","players":251},{"id":14,"name":"Duisburg (City)","country":"Germany","severity":"Congested","players":101},{"id":55,"name":"Calais (City)","country":"France","severity":"Congested","players":82},{"id":141,"name":"Calais - Duisburg (Intersection)","country":"Germany","severity":"Heavy","players":39},{"id":60,"name":"Paris (City)","country":"France","severity":"Low","players":39},{"id":57,"name":"Lille (City)","country":"France","severity":"Heavy","players":37},{"id":42,"name":"Amsterdam (City)","country":"Netherlands","severity":"Heavy","players":36},{"id":217,"name":"Calais (Intersection)","country":"France","severity":"Moderate","players":35}]}}';
    $arr = json_decode($json, true);
    echo $arr['response']['top'][0]['name'];
    ?>

    截图

     

    点赞 评论 复制链接分享
  • PHP_xiaozhang PHP_听风 1月前

    $a = json_decode("你的json");

    $name = $a['top']['name'];

    点赞 评论 复制链接分享
  • zhouhj008 zhouhj008 2月前

    你先用json_decode 解码,然后直接访问数组就可以了

    点赞 评论 复制链接分享
  • weixin_41509536 weixin_41509536 2月前

    如何取到"name": "Calais - Duisburg (Road)",中的数据

    点赞 评论 复制链接分享