Comment puis-je sélectionner des entrées spécifiques dans un fichier JSON?Multidimensional json php
{
"status" : "success",
"data" : {
"items" : [
{
"market_hash_name" : "AK-47 | Redline (Field-Tested)",
"total_items" : 923,
"lowest_price" : "4.00",
"highest_price" : "300.00",
"cumulative_price" : "8722.77",
"recent_sales_info" : {
"hours" : "18.07",
"average_price" : "4.21"
}
},
{
"market_hash_name" : "AK-47 | Redline (Minimal Wear)",
"total_items" : 51,
"lowest_price" : "14.26",
"highest_price" : "100.00",
"cumulative_price" : "1089.71",
"recent_sales_info" : {
"hours" : "23.37",
"average_price" : "14.36"
}
}
]
}
}
Screenshot:
Mon script PHP:
$steam = "AK-47 | Redline (Field-Tested)";
$link = 'list.json';
$string = file_get_contents($link);
$obj = json_decode($string);
if($obj->{'status'} == "success") die("notfound");
$lowest_price = $obj->{'lowest_price'};
$lowest_price[strlen($lowest_price)] = 0;
echo $lowest_price;
Comment puis-je choisir par exemple les "TOTAL_ITEMS" et le "Prix moyen" de Ak 47 Redline (testé sur le terrain)? Le market_hash_name est enregistré dans une variable et je veux enregistrer dans d'autres variables les valeurs associées.
Merci. Avec les meilleures salutations. Enge
'json_decode ($ str, true)' vous donne tableau –