#Alternatives to the deprecated JsonParser method

5 messages · Page 1 of 1 (latest)

zealous hatch
#

I've spent nearly an hour trying to find a workaround this snippet of code: JsonParser parser = new JsonParser(); JsonObject result = parser.parse(new InputStreamReader(conn.getInputStream())).getAsJsonObject();

I've looked up possible solutions, but none solve the issue of parser.parse() being deprecated. I saw that using static methods might solve this problem, but I'm uncertain as to how to go about that

eternal flameBOT
#

Hey, @zealous hatch!
Please remember to /close this post once your question has been answered!

azure swift
#
try(BufferedReader br=new BufferedReader(new InputStreamReader(new InputStreamReader(conn.getInputStream()),StandardCharsets.UTF_8)){
  JSONTokener tokener=new JSONTokener(br);
  JSONObject object = new JSONObject(tokener);
  //...
}