Hi I want to print exact data of maple but i doesnt work please help me there is some problem that i cant able to identify
$json = ' {
"Success":true,"Message":null,"Data":
{
"type": "donut",
"name": "Cake",
"toppings": [
{ "id": "5002", "type": "Glazed" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5004", "type": "Maple" }
]
}
}';
$yummy = json_decode($json, true);
echo $yummy['toppings'][2]['type']; //Maple
您错过了['Data']
:
$yummy['Data']['toppings'][2]['type']; //Maple `
print_r($yummy, true);
gives you json to array data.
Array
(
[Success] => 1
[Message] =>
[Data] => Array
(
[type] => donut
[name] => Cake
[toppings] => Array
(
[0] => Array
(
[id] => 5002
[type] => Glazed
)
[1] => Array
(
[id] => 5006
[type] => Chocolate with Sprinkles
)
[2] => Array
(
[id] => 5004
[type] => Maple
)
)
)
)
So you missed Data
$yummy['Data']['toppings'][2]['type']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.