我想将多个表中的数据返回到一个json对象,以便我可以在客户端反序列化其他对象的列表。客户端上的对象如下所示:
class LastSyncEntity
{
public List<OptionSettings> option { get; set; }
public List<Project> project { get; set;}
}
为此,我希望我在azure移动服务上的自定义API的json输出如下所示:
{
[
{option object 1}
{option object 2}
],
[
{project object 1}
{project object 2}
],
}
如何在服务器上获取javascript以使其像这样?我是javascript的新手。
答案 0 :(得分:0)
您提到的API的输出并不是真正有效的JSON。假设你想要这样的东西:
{
"option" : [
{ "option" : "object 1" },
{ "option" : "object 2" }
],
"project": [
{ "project" : "object 1" },
{ "project" : "object 2" }
]
}
然后您可以按如下方式实现API:
exports.get = function(request, response) {
var optionTable = request.service.tables.getTable('option');
var projectTable = request.service.tables.getTable('project');
optionTable.where(function() {
return true; // add any filtering for options here
}).read({
success: function(options) {
projectTable.where(function() {
return true; // add any filtering for projects here
}.read({
success: function(projects) {
var result = { option: options, project: projects };
response.send(200, result);
}
});
}
});
}