Tolgay Toklar Tolgay Toklar - 2 years ago 387
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download