简体   繁体   English

嵌套在JSONObject中的JAVA get Byte []

[英]JAVA get Byte[] nested in JSONObject

i need to get a response from a org.json.JSONObject (args). 我需要从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" 等于10个字符的String "[B@ffc06c8"

The following image is the args response in the debugger. 下图是调试器中的args响应。 i need to get the pointed out value. 我需要获得指出的价值。 在此处输入图片说明

how do i retreive the value as it in in the debugger? 我如何获取调试器中的值?

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). -> Log.d打印参考 (defaultResponce +“”将byte []转换为字符串)。 Is this why you think it's a string? 这就是为什么您认为它是字符串? check out if defaultResponce is an instance of byte[] or whatever you are looking for. 检查defaultResponce是否是byte []的实例或您要查找的内容。

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. 无论如何,如果标准API没有返回您要查找的内容,则始终可以使用反射来到达所需的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM