Tolgay Toklar Tolgay Toklar - 7 months ago 126
Java Question

Converting byte[] to JsonObject

I want to convert

byte
to
JsonObject
. I tried like this:

public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
JsonObject 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?

Answer

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 JSONObjectinto it.

Comments