[英]multidimensional array json_decode (first level)
我有一個像這樣的JSON文件:
{
"numeric1": {
"id": "numeric1",
"name": "alphanumeric1",
"key": "alphanumeric2",
"expire": "alphanumeric3",
"status": true,
"ads": true
},
etc...
}
與(等)我的意思是矩陣重復了更多次。 我用PHP解析它:
$allowed = json_decode(file_get_contents("allowed.json"), true);
然后我得到一個像這樣的數組:
Array
(
[0] => Array
(
[id] => numeric1
[name] => alphanumeric1
[key] => alphanumeric2
[expire] => alphanumeric3
[status] => 1
[ads] => 1
)
etc....
)
所以我失去了第一級的關聯密鑰,
[0] => Array代替
[“ numeric1”] =>數組
如何保留JSON數組的第一級? 謝謝。
嘗試這個:
$allowed = (array) json_decode(file_get_contents("allowed.json"));
因此,不是直接將JSON解析為數組(通過指定json_decode的第二個參數),而是首先獲取將保留密鑰的對象,然后將其轉換為數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.