I have the following array in PHP:
Array
(
[0] => Array
(
[id] => 0
[name] => name1
[short_name] => n1
)
[2] => Array
(
[id] => 2
[name] => name2
[short_name] => n2
)
)
I want to JSON encode it as a JSON array, producing a string like the following:
[
{
"id":0,
"name":"name1",
"short_name":"n1"
},
{
"id":2,
"name":"name2",
"short_name":"n2"
}
]
But when I call json_encode
on this array, I get the following:
{
"0":{
"id":0,
"name":"name1",
"short_name":"n1"
},
"2":{
"id":2,
"name":"name2",
"short_name":"n2"
}
}
Which is an object instead of an array.
How can I get json_encode
to encode my array as an array, instead?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…