我正在尝试获取一个api(steam api)响应作为变量。
INFO: y_in='{15,15,15,15,15}
INFO: y_in='{6'bzzzzzz,6'bzzzzzz,6'bzzzzzz,6'bzzzzzz,0}
INFO: y_in='{15,15,15,15,15}
INFO: y_in='{15,15,15,15,15}
INFO: y_in='{15,15,15,15,15}
格式化:https://pastebin.com/8QtLzwVX
当前,我正在使用以下代码来获取数组:
{"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}]}}
我不知道如何从在$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);
中获取的JSON获取 personaname 值,并将其放在类似$result
的变量中。
答案 0 :(得分:0)
尝试这个:
<?php
$json_array = json_decode($result, true);
echo $json_array['response']['players'][0]['personaname'];