Lonergan6275 Lonergan6275 - 1 year ago 158
JSON Question

JAVA get Byte[] nested in JSONObject

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download