Reputation: 63
String json1 = new Gson().toJson(list);
System.out.println(json1);
request.getSession().setAttribute("json1", json1);
I checked the logs it prints string like : ["090856","056986"]
In JSP I wrote something line below in script
var n = '<%= session.getAttribute("json1") %>';
alert(n);
The alert displayed 090856,056986
.
why such behaviour should not it display ["090856","056986"]
.
sometimes it also appears like this too
Upvotes: 1
Views: 89
Reputation: 6354
There is nothing wrong in your your code. alert is modifying the string while showing.
Use console.log(n)
to test your json string.
Or use JSON.stringify function
alert(JSON.stringify(n));
Upvotes: 1
Reputation: 1562
It's normal behaviour.
You can try directly in chrome console.
Upvotes: 2