I want to convert byte
to JsonObject
. I tried like this:
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String testV=new JsonObject(new String(responseBody));
}
But I am getting compiler error:
JsonObject cannot be applied to java.lang.String
How can I do this?
JSON does not support that. Use Base64. That is your library supporting it, not JSON itself. The byte array wont be stored as byte array in the JSON, JSON is a text format meant to be human readable.
JSON can be either an array or an object.
Try this :
String testV=new JSONObject(new String(responseBody)).toString();
or this if you need a JSONObject
JSONObject testV=new JSONObject(new String(responseBody));
The issue is that you declare a String
variable and intent to store a JSONObject
into it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With