Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing Map to JSON using JSON Simple

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!

like image 868
mumair Avatar asked Oct 21 '25 15:10

mumair


1 Answers

Try to use

//import org.json.simple.JSONValue;

String jsonText = JSONValue.toJSONString(map);
System.out.print(jsonText);

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!