This topic differs from subjects such as: "How to consume JSON in PHP string ; "Extract json value in php"; php "or" Recover JSON in PHP " Although there is co-relation in various PHP language subjects, and the JSON format, it deals with a specific problem, detailed in detail and summarized.
In all materials that deal with the subject of JSON in PHP, I find none that cite the different ways of treating JSON. They treat json as if it were always expressed in the same way, which is not true in practice. So we always have an algorithm for every way it is expressed. Is there a universal way of capturing the json data, or is there a specific way for the second case quoted below?
A practical example would be that this:
{
"friendslist":{
"friends":[
{
"steamid":"76561197960265731",
"relationship":"friend",
"friend_since":0
},
{
"steamid":"76561197960265738",
"relationship":"friend",
"friend_since":0
},
{
"steamid":"76561197960265740",
"relationship":"friend",
"friend_since":0
},
{
"steamid":"76561197960265747",
"relationship":"friend",
"friend_since":0
}
]
}
}
Certainly it's different than that:
[
{
"id":"578",
"valor":"4.00",
"CLIENTE":{
"id":"492",
"nome":"MARIA",
"sobrenome":"Machado",
"endereco":"Avenida das Am\u00e9ricas",
"latitude":null,
"longitude":null
},
"dataCompra":"DATA_AQUI",
"PRODUTOS":[
{
"id":"14135",
"codigoDeBarras":"7896015516260",
"nome":"SONRIDOR",
"detalhes":"500mg cx 60 comp",
"categoria":"medicamento",
"quantidade":"2",
"precoUnitario":".10"
}
],
"FRANQUIA":{
"id":"818",
"nomeFantasia":null,
"razaoSocial":null,
"rede":{
"id":"32",
"nome":"Sapataria João"
},
"endereco":"Rua Acre",
"latitude":"-22.899079",
"longitude":"-43.181612"
}
}
]
The first case, until I find a way to read
$steamid_player = "76561198112612121";
$apikey = "APIKEY";
$amg = file_get_contents("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=$apikey&steamid=$steamid_player&relationship=friend");
$decode = json_decode($amg, TRUE);
foreach ($decode["friendslist"]["friends"][0] as $valor){
$steamid = $valor["relationship"]->steamid;
echo $steamid;
}
But in the second case, I found no practical examples. I can do at most a vardump.