【发布时间】:2015-12-27 09:13:10
【问题描述】:
我必须通过PHP 从MongoDB 读取一些数据。
当我将MongoDB 结果转换为Json 时,我得到如下结果:
{
"records":
[
{
"_id":
{
"id": "567f18f21e2e328206d3d91e"
},
"title": "test",
"price": 5000,
"date": "1394-09-05 11:30",
"images":
[
{
"_id":
{
"id": "567f18f21e2e328206d3d91f"
},
"url": "a"
},
{
"_id":
{
"id": "567f18f21e2e328206d3d920"
},
"url": "x"
},
{
"_id":
{
"id": "567f18f21e2e328206d3d921"
},
"url": "c"
}
]
}
]
}
如您所见,我们有一个如下所示的 id:
"_id":
{
"$id": "567f18f21e2e328206d3d91e"
},
当我想用 Java 解析这个 json 时,它给我带来了一些问题,我想把它转换成这样的东西:
{
"records":
[
{
"id": "567f18f21e2e328206d3d91e"
"title": "test",
"price": 5000,
"date": "1394-09-05 11:30",
"images":
[
{
"id": "567f18f21e2e328206d3d91f",
"url": "a"
},
{
"id": "567f18f21e2e328206d3d920",
"url": "x"
},
{
"id": "567f18f21e2e328206d3d921",
"url": "c"
}
]
}
]
}
我该怎么做?
我不能使用foreach 方法来编辑这个数组,因为我有无限的子数组
【问题讨论】: