0

i need to get a response from a org.json.JSONObject (args).

new Emitter.Listener() {
    @Override
    public void call(Object... args) {

         try {
             JSONObject response = new JSONObject(args[0].toString());

             JSONObject data = (JSONObject) response.get("data");
             Object defaultResponce = data.get("default");

             Log.d(TAG, defaultResponce + "");
         }
         catch (JSONException e) {
             e.printStackTrace();
         }
     }
}

Object defaultResponce = data.get("default"); equates to a 10 character, String "[B@ffc06c8"

The following image is the args response in the debugger. i need to get the pointed out value. enter image description here

how do i retreive the value as it in in the debugger?

10
  • How did you get a byte array into a JSON object? What does args[0].toString() contain? Commented Jul 20, 2016 at 11:31
  • It is a response from a Socket.io emit request. i was expecting it to be a more jason with key value pairs Commented Jul 20, 2016 at 11:36
  • I don't really get your question, but the issue seems to be that you put the "toString" output of the array instance into the JSON output, instead of the data of the array. I think you need to explicitly convert the Java array to a JSON array. Commented Jul 20, 2016 at 11:36
  • Or maybe you just SEE the toString output, but the defaultResponce object (by the way, it is spelled "response") indeed is an array? Does it show as an array in the debugger? What about instanceof? Commented Jul 20, 2016 at 11:37
  • If you use org.json.JSONObject you are on android, right? Commented Jul 20, 2016 at 11:39

1 Answer 1

2

I think you got mixed up a bit...

Object defaultResponce = data.get("default");
Log.d(TAG, defaultResponce + "");

--> The Log.d prints the reference (defaultResponce + "" converts the byte[] to string). Is this why you think it's a string? check out if defaultResponce is an instance of byte[] or whatever you are looking for.

Anyway, you can always use reflection to get to the field you want if the standard API doesn't return what you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.