Android and Azure Mobile Services: Using invokeAPI to return recordset

给你一囗甜甜゛ 提交于 2019-12-03 20:04:19

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));
            }
        }
    });

I haven't had a chance to test it yet (will try when I have time and edit answer as needed) but my thinking is that the Android SDK won't allow you to do what you're trying to do. The invokeApi methods expect a strongly typed class to be set as the response type (or you can use the raw JSON methods). In this case, you're trying to say you want a list of items back, but I don't think that will work. I think you'll instead need to create a new class (i.e. missingvehiclesfrominventoryjobResponse) which contains a property that is of type List< InventoryProspects>. Note that you'll need to change your method call to actually match one of the available options for invokeApi which I don't believe it's doing right now. You can read more about the different formats of the method here: http://blogs.msdn.com/b/carlosfigueira/archive/2013/06/19/custom-api-in-azure-mobile-services-client-sdks.aspx

Alternatively, you can use the table methods against a table endpoint where the read expects a collection of results back.

Dchaser88

Have you tried to remote debug your API call from the app.[http://blogs.msdn.com/b/azuremobile/archive/2014/03/14/debugging-net-backend-in-visual-studio.aspx]. Your app will timed out in doing that but you can see line by line execution of your controller action if it returns the correct result set. If there is no problem with it then the problem should be in parsing result set.

What is the exception you are getting in callback? And have you tried using other method parameters such as passing with different HTTP methods? Use this as a reference as well. http://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started/

Please paste your exception or either controller action, and the object structure of the data transfer object of the result set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!