PHP Json解析6
如何从中拔出76561198216468627PHP Json解析6,php,json,Php,Json,如何从中拔出76561198216468627 { "response": { "steamid": "76561198216468627", "success": 1 } } 我试过这个,但它拉1而不是id foreach ($parsed_json->{'reponse'} as $item) { $steamid = $item; } 您需要将JSON字符串解码为PHP对象或数组。以下是每种方法的操作方法: 数组方法 $jsonString = '{ "response"
{ "response": { "steamid": "76561198216468627", "success": 1 } }
我试过这个,但它拉1而不是id
foreach ($parsed_json->{'reponse'} as $item) {
$steamid = $item;
}
您需要将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;
}
对象方法
$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;
}
您需要将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;
}
对象方法
$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;
}
试试这个:
$json = '{
"response": [{ "steamid": "76561198216468627", "success": 1 }]
}';
$decode = json_decode($json);
echo $decode->response[0]->steamid;
然后您可以获得76561198216468627试试以下方法:
$json = '{
"response": [{ "steamid": "76561198216468627", "success": 1 }]
}';
$decode = json_decode($json);
echo $decode->response[0]->steamid;
然后,您可以得到76561198216468627您的代码正在该解析json中的response属性值上迭代。您希望直接访问steam ID。这样做而不是迭代。您的代码正在迭代解析的json中响应属性的值。您希望直接访问steam ID。这样做,而不是迭代。