How to convert String to JsonObject

Revils picture Revils · Sep 20, 2014 · Viewed 82.8k times · Source

I am using a httprequest to get Json from a web into a string.

It is probably quite simple, but I cannot seem to convert this string to a javax.json.JsonObject.

How can I do this?

Answer

fracz picture fracz · Sep 20, 2014
JsonReader jsonReader = Json.createReader(new StringReader("{}"));
JsonObject object = jsonReader.readObject();
jsonReader.close();

See docs and examples.