我有一个通过 json_encode 传递的数组,它将数组括号包裹在第一个数组周围,但将对象附件 {} 包裹在第二个数组周围并为嵌套数组编号。它没有引起任何错误,只是想知道为什么会这样。
{
"data": {
"first_array": [
{
"meta": {
"slug": "rank",
"weight": "100",
"description": "lorem ipsum",
"importance": {
"value": 2,
"max": 5
}
},
"scores": {
"results": {
"slug": "rank",
"type": "int",
"value": "4"
}
}
},
{
"meta": {
"slug": "rank",
"weight": "100",
"description": "lorem ipsum",
"importance": {
"value": 2,
"max": 5
}
},
"scores": {
"results": {
"slug": "rank",
"type": "int",
"value": "4"
}
}
}
],
"second_array": {
"2": {
"meta": {
"slug": "this",
"weight": "75",
"description": "lorem ipsum",
"importance": {
"value": 1,
"max": 5
}
},
"scores": {
"results": {
"slug": "this",
"type": "boolean",
"value": 1,
"code": 200
}
}
},
"3": {
"meta": {
"slug": "that",
"weight": "200",
"description": "lorem ipsum",
"importance": {
"value": 3,
"max": 5
}
},
"scores": {
"results": {
"slug": "that",
"type": "boolean",
"value": 1
}
}
}
}
}
}
这是数组的 print_r
Array
(
[data] => Array
(
[first_array] => Array
(
[0] => Array
(
[meta] => Array
(
[slug] => rank
[weight] => 100
[description] => lorem ipsum
[importance] => Array
(
[value] => 2
[max] => 5
)
)
[scores] => Array
(
[results] => Array
(
[slug] => rank
[type] => int
[value] => 4
)
)
)
[1] => Array
(
[meta] => Array
(
[slug] => rank
[weight] => 100
[description] => lorem ipsum
[importance] => Array
(
[value] => 2
[max] => 5
)
)
[scores] => Array
(
[results] => Array
(
[slug] => rank
[type] => int
[value] => 4
)
)
)
)
[second_array] => Array
(
[2] => Array
(
[meta] => Array
(
[slug] => this
[weight] => 100
[description] => lorem ipsum
[importance] => Array
(
[value] => 2
[max] => 5
)
)
[scores] => Array
(
[results] => Array
(
[slug] => this
[type] => boolean
[value] => 1
[code] => 200
)
)
)
[3] => Array
(
[meta] => Array
(
[slug] => that
[weight] => 100
[description] => lorem ipsum
[importance] => Array
(
[value] => 2
[max] => 5
)
)
[scores] => Array
(
[results] => Array
(
[slug] => that
[type] => boolean
[value] => 1
)
)
)
)
)
)