我试图通过使用json_encode
转换php数组来复制这个json:
"sort" : [
{ "age" : "desc" },
"_score"
]
使用以下PHP数组:
$json_doc['sort'] = array(
"_score",
"age"=>"desc"
);
如果我只是在数组中得分,PHP正确地没有为数组分配一个键:
"sort" : [
"_score"
]
但是当我将"age"=>"desc"
混合到混合中时,json_encode
无法正确编码_score
:
"sort": {
"0": "_score",
"age": "desc"
}
答案 0 :(得分:2)
$json_doc['sort'] = Array(
"_score",
Array('age' => 'desc')
);