我怎么才能把76561198216468627从
{ "response": { "steamid": "76561198216468627", "success": 1 } }
我试过了,但是它拉了1而不是id
foreach ($parsed_json->{'reponse'} as $item) {
$steamid = $item;
}
发布于 2017-04-20 02:02:22
您需要将JSON字符串解码为PHP对象或数组。以下是如何做到每一种方式:
阵列方法
$jsonString = '{ "response": { "steamid": "76561198216468627", "success": 1 } }';
$json = json_decode($jsonString, true);
foreach($json as $item)
{
$steamid = $item['steamid'];
}
对象方法
$jsonString = '{ "response": { "steamid": "76561198216468627", "success": 1 } }';
$json = json_decode($jsonString);
foreach($json as $item)
{
$steamid = $item->steamid;
}
发布于 2017-04-20 02:21:08
试试这个:
$json = '{
"response": [{ "steamid": "76561198216468627", "success": 1 }]
}';
$decode = json_decode($json);
echo $decode->response[0]->steamid;
那你就能得到76561198216468627
https://stackoverflow.com/questions/43508874
复制相似问题