Json line separator issue

Ok i'm stuck here i have a json output given from the code above

    $jsonurl = 'http://us.battle.net/api/d3/profile/'.$btag.'/';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);

i can retrieve the data using, for example

$json_output->code

but, i have a specific data i need to retrieve

$json_output->timePlayed->demon-hunter

this one i cant retrieve because of the "-" in side the "demon-hunter" any tips?

Upvotes: 0

Views: 301

Answers (2)

kodeart
kodeart

Reputation: 1903

$type = 'demon-hunter';
$json_output->timePlayed->$type;

Upvotes: 0

sroes
sroes

Reputation: 15053

Yeah, either use arrays:

$json_output = json_decode($json, true);
$json_output['timePlayed']['demon-hunter'];

Or use the following notation:

$json_output->timePlayed->{'demon-hunter'}

Upvotes: 5

Related Questions