How to convert hashmap to JSON object in Java

前端 未结 29 2347
谎友^
谎友^ 2020-11-22 11:20

How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?

29条回答
  •  孤城傲影
    2020-11-22 11:43

    For those using org.json.simple.JSONObject, you could convert the map to Json String and parse it to get the JSONObject.

    JSONObject object = (JSONObject) new JSONParser().parse(JSONObject.toJSONString(map));
    

提交回复
热议问题