0

I am developing an android app which connects a python server through JSON. I am now encountering a bug that hinders the connection between the android client and python server.

Since pyjsonrpc never include the key "error" in its response JSON string, android-json-rpc package throws an exception about finding no "error" key in the response.

The exception is thrown in the file JSONRPCHttpClient.class

        responseString = responseString.trim();
        JSONObject jsonResponse = new JSONObject(responseString);
        Object jsonError = jsonResponse.get("error");
        if(!jsonError.equals((Object)null)) {
            throw new JSONRPCException(jsonError);
        } else {
            return jsonResponse;
        }

I am not sure it is a practice to add "error" in to response JSON since I am quite new to android development. Is there any sophisticate way to work around this?

The exception thrown is: org.json.JSONException: No value for error

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I am using pyjsonrpc package for server side json interface – Alabama GanGan Nov 11 '15 at 08:28
  • So, what is the message you need from `jsonResponse` ? is it must contains "error" ? and if so, what is the format of it (e.g String, JSONObject, int, ...etc) ? – Muhammed Refaat Nov 11 '15 at 08:44
  • It returns a standard item not found error: – Alabama GanGan Nov 11 '15 at 09:01
  • what do you mean by a standard item? can you please edit your question with the response you waiting from it and the response you actually get "responseString" ? – Muhammed Refaat Nov 11 '15 at 09:27
  • The exception thrown is: org.json.JSONException: No value for error. I know its from the line `Object jsonError = jsonResponse.get("error")` but I cannot modified the code since it is decompiled from .jar. – Alabama GanGan Nov 11 '15 at 09:36
  • that means there is no object called "error" in the json of `responseString`, so what do you want to do about that? just looking for error or passing this code without exceptions. it will help a little if you printed here what `responseString` contains. – Muhammed Refaat Nov 11 '15 at 11:18

1 Answers1

0

Turns out the "Latest package" link on the front page of the android-json-rpc package is not latest. They fixed this issue on latter package. More importantly I understand that "error" is not a standard JSON reponse key and it only shows when there are server side errors.

Thanks for the help!