好吧,我被困在这里了我有一个从上面的代码给出的 JSON 输出
$jsonurl = 'http://us.battle.net/api/d3/profile/'.$btag.'/';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
例如,我可以使用以下方法检索数据
$json_output->code
但是,我有一个特定的数据需要检索
$json_output->timePlayed->demon-hunter
这个我无法检索,因为"恶魔猎手"旁边的"-"有什么提示吗?
是的,要么使用数组:
$json_output = json_decode($json, true);
$json_output['timePlayed']['demon-hunter'];
或者使用以下表示法:
$json_output->timePlayed->{'demon-hunter'}
$type = 'demon-hunter';
$json_output->timePlayed->$type;