我知道,为什么 JSON编码数据(来自MongoDB,通过PHP)显示为:
{
"53a6e02221360e263e000000": {
"_id": {
"$id": "53a6e02221360e263e000000"
},
"title": "1"
},
"53a6e02221360e263e000001": {
"_id": {
"$id": "53a6e02221360e263e000001"
},
"title": "2"
}
}
很糟糕,但是:
[
{
"id": "53a6e02221360e263e000000",
"title": "1"
},
{
"id": "53a6e02221360e263e000001",
"title": "2"
}
]
好吗?
有什么想法吗?两者都是有效的JSON。
PHP代码示例:
// MongoDB init before it
$cursor = $mongo->db->collection->find();
// For not large data
$result = iterator_to_array( $cursor );
$json = json_encode($result);
var_dump($json);