【发布时间】:2018-10-24 18:23:00
【问题描述】:
我正在尝试获取 api(steam api) 响应作为变量。
{"response":{"players":[{"steamid":"XXXXXXXXXXXXXXXXXXXX","communityvisibilitystate":3,"profilestate":1,"personaname":"The value I want to get","lastlogoff":XXXXXXXXXX,"profileurl":"XXX","avatar":"X","avatarmedium":"X","avatarfull":"X","personastate":1,"realname":"X","primaryclanid":"X","timecreated":XXXXXXXXXX,"personastateflags":0}]}}
格式化:https://pastebin.com/8QtLzwVX
目前我正在使用以下代码来获取数组:
$url="http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamids=" . $sid;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
我不知道如何从我在$result 中得到的 JSON 中获取 personaname 值并将其放入像 $personaname 这样的变量中。
【问题讨论】:
-
你试过
json_decode吗? -
@DavidWinder 是的。
json_decode($result, true). -
你能在
curl_exec之后显示$result的var_dump吗?
标签: php arrays json curl steam-web-api