Peter Pik
Peter Pik

Reputation: 11193

Retrieve object in json using php

i'm trying to retrieve an JSON object in php however whatever i try it just return 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.

JSON object:

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

Upvotes: 0

Views: 67

Answers (2)

Dimitri Acosta
Dimitri Acosta

Reputation: 1816

Try to remove the true option in the json_decode function to make it looks like this

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

Upvotes: 0

MegaAppBear
MegaAppBear

Reputation: 1220

Try:

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

Upvotes: 1

Related Questions