这是JSON数据
{"clanSearch":{"results":[{"tag":"#G90G8RCU","name":"codex2015.asia","type":"open","locationName":"Indonesia","clanBadgeImg":{"s":"https://api-assets.clashofclans.com/badges/70/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png, https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png 2x","m":"https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png, https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png 2x","l":"https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png","xl":"https://api-assets.clashofclans.com/badges/200/FDduXa8Fmz_KmJyPsFTTms00YDykkmlZRu4ev-juBQQ.png"},"warFrequency":"always","clanLevel":1,"clanPoints":6867,"warWins":0,"requiredTrophies":0,"members":12}]}}
Here is the link
和我的PHP代码
$json = json_decode(file_get_contents("https://set7z18fgf.execute-api.us-east-1.amazonaws.com/prod/?route=getClanSearch&name=codex2015.asia"));
$info = "$json->{'tag'}";
echo $info;
在这种情况下,我想获取标签数据,但如果我运行此脚本,我什么也得不到。
答案 0 :(得分:2)
$json = json_decode(trim(file_get_contents("url",true)));
$info = $json['clanSearch']['results'][0]['tag'];
echo $info;
使用true
标志,并将孔数据转换为具有子数组的数组
如果你不使用true
,你必须得到它:
$json->clanSearch->results[0]->tag;