[英]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.