我正在开发一个WEB API,需要以这种格式返回json结果:
{
"responseID": "b806d829-1d9c-4c69-8d7a-576ffc4de555",
"orders": [
{
"id": order1,
"status": "Issued",
"statusDate": "2017-04-05T10:00:56.1549453+00:00",
"amount": 100000,
"quantity": 10,
"fee": 99,
"comments": "some comments"
},
{
"id": order2,
"status": "Declined",
"statusDate": "2017-04-05T10:00:56.1549453+00:00",
}
]
}
我们可以准备一个这样的json对象,其中数组中的对象具有不同的属性,如上例所示,order1有7个属性,但order2只有3个。
我的理解是,实现所需结果的唯一方法是更改json对象的格式,如下所示:
{
"responseID": "b806d829-1d9c-4c69-8d7a-576ffc4de555",
"issuesOrders": [
{
"id": order1,
"status": "Issued",
"statusDate": "2017-04-05T10:00:56.1549453+00:00",
"amount": 100000,
"quantity": 10,
"fee": 99,
"comments": "some comments"
} ],
"declinedOrders": [
{
"id": order2,
"status": "Declined",
"statusDate": "2017-04-05T10:00:56.1549453+00:00",
}
]
}
我的理解是否正确?