Put/get byte array value using JSONObject

前端 未结 4 997
孤街浪徒
孤街浪徒 2021-01-13 17:03

I tried to get my byte[] value from JSONObject using following code but I am not getting original byte[] value.

JSONAr         


        
4条回答
  •  渐次进展
    2021-01-13 17:53

    When inserting a byte array into a JSONObject the toString() method is invoked.

    public static void main(String... args) throws JSONException{
        JSONObject o = new JSONObject();
        byte[] b = "hello".getBytes();
        o.put("A", b);
        System.out.println(o.get("A"));
    }
    

    Example output:

    [B@1bd8c6e
    

    so you have to store it in a way that you can parse the String into the original datatype.

提交回复
热议问题