簡體   English   中英

使用php檢索json中的對象

[英]Retrieve object in json using php

我正在嘗試在php中檢索JSON對象,但是無論我如何嘗試,都只是返回null。 到目前為止,我已經嘗試遵循:

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

其中$ obj是JSON解碼的JSON對象。

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"
        ]
    }
    ]
}

嘗試:

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

嘗試刪除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