1.data.json文件
{
"goods":[
{
"type":1,
"name":"wow精選",
"product":[
{
"id":98,
"name":"真皮大衣",
"title":"單桶原釀酒 威士忌 新春禮盒 限量獨家",
"titleDesc":"蘇格蘭麥芽糖,中國定製版",
"price":1298.00
},
{
"id":99,
"name":"品牌內衣",
"title":"單桶原釀酒 威士忌 新春禮盒 限量獨家222",
"titleDesc":"蘇格蘭麥芽糖,中國定製版222",
"price":1298.00
}
]
},
{
"type":2,
"name":"特惠商品",
"product":[]
}
]
}
2.php文件
// 從文件中讀取數據到PHP變量
$json_string = file_get_contents('static/json/shield.json');
// 用參數true把JSON字符串強制轉成PHP數組
$data = json_decode($json_string, true);