1

I commit an InputStream in from class1 to class2. Now I want to parse the InputStream in class2 to a JSONObject.

try {
        JsonElement element = new JsonParser().parse(new InputStreamReader(in));
        JSONObject jsonObject = new JSONObject(element.getAsJsonObject().toString());
} catch (JSONException e) {
        System.err.println(e.getMessage());
}

My JsonElementelement is null. So I get no JSONObject.

I use the same Code in class1 and it works. The only difference is, that the InputStream is generated in class1 with HTTPHandler.execute(...).

class1 commits the InputStream correct to class2.

angelika285
  • 255
  • 1
  • 3
  • 12

1 Answers1

1

You could use JsonReader, which supports read json from an Input Stream, and the ref doc provides an detailed example.

navylover
  • 12,383
  • 5
  • 28
  • 41