How to convert String to JsonObject

后端 未结 2 637
清酒与你
清酒与你 2021-01-01 09:20

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

相关标签:
2条回答
  • 2021-01-01 10:02

    Since the above reviewer didn't like my edits, here is something you can copy and paste into your own code:

    private static JsonObject jsonFromString(String jsonObjectStr) {
    
        JsonReader jsonReader = Json.createReader(new StringReader(jsonObjectStr));
        JsonObject object = jsonReader.readObject();
        jsonReader.close();
    
        return object;
    }
    
    0 讨论(0)
  • 2021-01-01 10:04
    JsonReader jsonReader = Json.createReader(new StringReader("{}"));
    JsonObject object = jsonReader.readObject();
    jsonReader.close();
    

    See docs and examples.

    0 讨论(0)
提交回复
热议问题