[英]how to get json value that has no key
i am using php to get the json values and have no problem looping though the data and echoing the SteamName, Level, Experience and more. 我正在使用php获取json值,并且遍历数据并回显SteamName,Level,Experience等都没有问题。 However I do not know how to echo the steamid number 7656119801319... per proile. 但是,我不知道如何在每个堆中回显水凝体编号7656119801319...。
json file: json文件:
{
"FURNACES": {},
"PROFILE": {
"76561198013191579": {
"SteamName": "Cayos",
"Level": 22,
"Experience": 1592,
"Agility": 22,
"Strength": 22,
"Intelligence": 22,
"StatsPoints": 66,
"SkillPoints": 2,
"Skills": {
"lumberjack": 20
},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"76561198113765447": {
"SteamName": "CaptainCheesy",
"Level": 31,
"Experience": 3576,
"Agility": 31,
"Strength": 70,
"Intelligence": 70,
"StatsPoints": 15,
"SkillPoints": 5,
"Skills": {
"miner": 8,
"lumberjack": 10,
"hunter": 8
},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"76561198141845337": {
"SteamName": "Carrot",
"Level": 3,
"Experience": 409,
"Agility": 3,
"Strength": 3,
"Intelligence": 3,
"StatsPoints": 9,
"SkillPoints": 3,
"Skills": {},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"76561198012539649": {
"SteamName": "Booglee",
"Level": 3,
"Experience": 110,
"Agility": 3,
"Strength": 3,
"Intelligence": 3,
"StatsPoints": 9,
"SkillPoints": 3,
"Skills": {},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"333228975": {
"SteamName": "SYN Gaurd",
"Level": 0,
"Experience": 0,
"Agility": 0,
"Strength": 0,
"Intelligence": 0,
"StatsPoints": 0,
"SkillPoints": 0,
"Skills": {},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
}
}
}
My PHP Code: 我的PHP代码:
$url = 'C:\Users\plosey\Desktop\GameServers\Rust\steam\server_syn1\server\syn1\oxide\data\Hunt_Data.json'; //Url to the cars api
$content = file_get_contents($url);
$json = json_decode($content);
foreach($json->PROFILE as $user) {
echo $user->SteamName;
echo $user->NEED STEAM ID HERE; // This is the line that is not correct.
}
so in short i would need to not only echo the SteamName but the Steamid number from the same profile. 简而言之,我不仅需要回显SteamName,还需要回显来自同一配置文件的Steamid编号。
Instead of 代替
foreach($json->PROFILE as $user) {
use 采用
foreach ($json->PROFILE as $steamid => $user) {
Try below code to print id. 尝试下面的代码来打印ID。 $stremId will print your ID. $ stremId将打印您的ID。 You can replace it with any variable name. 您可以将其替换为任何变量名称。
$json = json_decode($json);
foreach($json->PROFILE as $streamId => $user) {
echo $user->SteamName;
echo $streamId;
}
try this 尝试这个
foreach($json->PROFILE as $key => $user) {
echo $key .' => '.$user->SteamName."<br/>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.