I am using Gson library to convert Map to JSON. But requirement is to use json-simple-1.1.1. I google for solution but my bad luck couldn't get solution.
I want to use JSON Simple to achieve following operation:
/** Converting Map to JSON and sending response back to view */
private void write(HttpServletResponse response, Map<String, Object> map) throws IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(new Gson().toJson(map));
}
any help is appreciated!
Try to use
//import org.json.simple.JSONValue;
String jsonText = JSONValue.toJSONString(map);
System.out.print(jsonText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With