How to convert or cast hashmap to JSON object in Java, and again convert JSON object to JSON string?
If you are using net.sf.json.JSONObject
then you won't find a JSONObject(map)
constructor in it. You have to use the public static JSONObject fromObject( Object object )
method. This method accepts JSON formatted strings, Maps, DynaBeans and JavaBeans.
JSONObject jsonObject = JSONObject.fromObject(myMap);