I am using struts2 for Action and jquery for UI …
I want to know how to convert a Map object to JSON object and send it back to UI ,
Now am able to print it in JSP page the normal java Map object :
{71=Heart XXX, 76=No Heart YYY}
But i want it to be like this :
{71:Heart XXX, 76:No Heart YYY}
How will i achieve this …. ?
Try Gson:
I wouldn’t recommend putting this kind of code into a JSP, though. Things like these should live in a controller like a Servlet or Action class.
You also most definitely don’t want the output to be:
but rather proper JSON like (quoted names, quoted string values):
Gson will output the latter.