http://stackoverflow.com/questions/23472205/android-and-azure-mobile-services-using-invokeapi-to-return-recordset
Essentially, the Android custom API for Android seems to only want to handle a single value, not at list.
My solution was to use the JSON version of the call, rather than the typed on, and then parse the JSON to get values, like this:
JsonObject request = new JsonObject();
request.addProperty("propertyname", value);
mClient.invokeApi("myapi", request, new ApiJsonOperationCallback() {
@Override
public void onCompleted(JsonElement result, Exception error,
ServiceFilterResponse response) {
doneWorking();
JSONArray myResults;
try {
myResults = new JSONArray(result.toString());
processResult(myResults);
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.v("MyApp", "Failed");
}
}
});
public void processResult(JSONArray myResults){
String voteoption;
String votes;
for(int n = 0; n < myResults.length(); n++)
{
try{
JSONObject res = myResults.getJSONObject(n);
voteoption = res.getString("voteoption");
votes = res.getString("votes");
// do something with vote option and votes
}
catch (JSONException e)
{
Log.v("MyApp", "Error sorting out the array " );
}
}
}
I'm probably missing something, as the iPhone version of the API call works as expected with multiple values.
A bittersweet ending to a day of scouring the web for a solution to this problem, but thanks very much for sharing your fix!
ReplyDelete