Tolgay Toklar Tolgay Toklar - 10 months ago 203
Java Question

Converting byte[] to JsonObject

I want to convert

. 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?


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.