Android和Azure的移动服务:使用invokeAPI返回记录集 [英] Android and Azure Mobile Services: Using invokeAPI to return recordset
问题描述
我想很简单的东西。我有一个名为missingvehiclesfrominventoryjob的自定义API,它只是返回从标准的SQL查询创下了一个纪录。
I am trying something very simple. I have a custom API called "missingvehiclesfrominventoryjob" and it simply returns a record set from an standard SQL Query.
我可以在我的WinForms和Windows Phone应用程序做到这一点很容易,但我无法弄清楚如何做到这一点的Android应用程序。
I can do this in my WinForms and Windows Phone app easily but I cannot figure out how to do this on the Android App.
下面是我的code:(不Android Studio中编译):
Here is my code: (which DOES NOT COMPILE in Android Studio):
msClient.invokeApi("missingvehiclesfrominventoryjob", kd, new
ApiOperationCallback<List<InventoryProspects>>(){
@Override
public void onCompleted(List<InventoryProspects> missingVehicles, Exception e,
ServiceFilterResponse serviceFilterResponse){
for (InventoryProspects item : missingVehicles){
mAdapter.add(item);
}
}
});
问题是在列表中的回调的参数即可。我不知道如何表明invoiceAPI通话将被从数据库返回多个行,我不能在任何地方文档找到解释如何。我也不能在互联网上找到一个示例的任何地方。
The problem is the List in the parameters of the Callback. I am not sure how to indicate that the invoiceAPI call will return multiple rows from the database and I cannot find anywhere in the docs to explain how. Nor can I find an example ANYWHERE on the internet.
我相信我不是唯一在试图做到这一点。
I am sure I am not the only on trying to do this.
在此先感谢
查克·吉登斯
推荐答案
我做了什么来解决这个问题,是调用invokeApi一个返回JsonElement不同的过载,然后deserialise到我的对象,像这样:
What i did to overcome this problem, is to call a different overload of invokeApi that returns a JsonElement, and then deserialise it into my objects like so:
mClient.invokeApi("MyCustomApi",null, "GET", null, new ApiJsonOperationCallback() {
@Override
public void onCompleted(JsonElement jsonElement, Exception e, ServiceFilterResponse serviceFilterResponse) {
GsonBuilder gsonb = new GsonBuilder();
Gson gson = gsonb.create();
JsonArray array = jsonElement.getAsJsonArray();
List<MyObject> myObjects = new ArrayList<MyObject>()>
for(int i = 0; i < array.size(); i++)
{
myObjects.add(gson.fromJson(array.get(i).getAsJsonObject().toString(), MyObject.class));
}
}
});
这篇关于Android和Azure的移动服务:使用invokeAPI返回记录集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!