1
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

Alert Message

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
  • 1
    Possible duplicate of [How can I view array structure in javascript with alert()?](http://stackoverflow.com/questions/3006644/how-can-i-view-array-structure-in-javascript-with-alert) – Greg Apr 27 '16 at 06:56

2 Answers2

2

It's normal behaviour.

You can try directly in chrome console.

  1. List item
  2. Go to chrome
  3. Press F12
  4. Go to Console tab
  5. Enter command : alert( ["090856","056986"]);
  6. As a result you have the following alert box

enter image description here

yurko
  • 1,502
  • 1
  • 13
  • 14
1

There is nothing wrong in your your code. alert is modifying the string while showing.

  1. Use console.log(n) to test your json string.

  2. Or use JSON.stringify function

    alert(JSON.stringify(n));
    
mirmdasif
  • 6,014
  • 2
  • 22
  • 28
  • @BineetKumarNayak welcome. Consider accepting an answer if it solves your problem. It will be helpful for others who face the same problem. – mirmdasif Apr 28 '16 at 05:21