简体   繁体   English

使用php检索json中的对象

[英]Retrieve object in json using php

i'm trying to retrieve an JSON object in php however whatever i try it just return null. 我正在尝试在php中检索JSON对象,但是无论我如何尝试,都只是返回null。 So far i've tried to following: 到目前为止,我已经尝试遵循:

$json = file_get_contents('BELOW JSON CODE');
$obj = json_decode($json,true);
var_dump($obj->live);

where $obj is the json decoded JSON object. 其中$ obj是JSON解码的JSON对象。

JSON object: JSON对象:

{
    "live": [
    {
        "match_id": "65545",
        "has_vods": false,
        "game": "hearthstone",
        "team 1": {
        "score": "",
        "name": "World Elite HS",
        "bet": "68%"
        },
        "team 2": {
        "score": "",
        "name": "ViCi Gaming",
        "bet": "32%"
        },
        "live in": "Live",
        "title": "World Elite HS 68% vs 32% ViCi Gaming...",
        "url": "http://www.gosugamers.net/hearthstone/tournaments/5636-nel-2015-winter/1478-group-stage/5638-group-b/matches/65545-world-elite-hs-vs-vici-gaming-hearthstone",
        "tounament": "http://www.gosugamers.net/",
        "simple_title": "World Elite HS vs ViCi Gaming...",
        "streams": [
        "http://www.twitch.tv/widgets/live_embed_player.swf?channel=Curemew"
        ]
    }
    ]
}

Try: 尝试:

$json = file_get_contents('BELOW JSON CODE');
$obj = json_decode($json); //<-- decode as object and not associative array
var_dump($obj->live);

Try to remove the true option in the json_decode function to make it looks like this 尝试删除json_decode函数中的true选项,使其看起来像这样

$json = file_get_contents('BELOW JSON CODE');
$obj = json_decode($json);
var_dump($obj->live);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM