【发布时间】:2016-08-26 20:12:00
【问题描述】:
好的,这是我第一次在这个网站上发帖。我需要一点帮助,我正在尝试将 json API 中的数据添加到 html 表中。这是我目前所拥有的。
<?php
$gamertag = 'x0--ii';
$jsonurl = 'https://tusticles.com/psn/api?psn='.$gamertag;
$json = file_get_contents($jsonurl);
var_dump(json_decode($json));
<?
这是我的输出:
object(stdClass)#1 (2) { ["status"]=> string(3) "200" ["response"]=> object(stdClass)#2 (5) { ["onlineId"]=> string(6) "x0--II" ["avatar"]=> string(77) "http://static-resource.np.community.playstation.net/avatar_m/SCEI/I0053_m.png" ["plus"]=> int(0) ["aboutMe"]=> string(0) "" ["trophies"]=> object(stdClass)#3 (6) { ["trophyLevel"]=> int(3) ["progress"]=> int(7) ["platinum"]=> int(0) ["gold"]=> int(2) ["silver"]=> int(6) ["bronze"]=> int(19) } } }
我想显示图像以及所有值。感谢您的帮助!
【问题讨论】:
-
解码 json 后,它就像 PHP 中的任何其他数据结构一样。您访问结构中的数据的方式与访问任何其他结构的方式完全相同。
-
是的,如果您想像访问数组一样访问它,请使用
json_decode($json, true)。否则,您需要使用->作为属性。你刚刚环绕<img src="">标签的图像。