【发布时间】:2016-06-30 10:33:09
【问题描述】:
我在 Servlet 上有以下代码
Map<String, Object> data = new HashMap<String, Object>();
data.put( "x", "[[0, 29.9],[1, 71.5],[3, 106.4]]" );
data.put( "y", "[[0.5, 28],[1.5, 60],[3, 100]]" );
data.put("z","[[0.2, 20],[1.5, 40],[3, 120]]");
JSONObject json = new JSONObject();
json.putAll( data );
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().println(json);
在页面中我尝试读取每个值,例如
$.getJSON("http://localhost:8080/HEC/someservlet", function(data) {
$.each(data, function(key, val) {
console.log(key+' '+ val);
});
});
问题是在控制台打印的每个值都删除了 [ ]
x 0,29.9,1,71.5,3,106.4
y 0.5,28,1.5,60,3,100
z 0.2,20,1.5,40,3,120
我期待看到这个
x [[0,29.9],[1,71.5],[3,106.4]]
y [[0.5,28],[1.5,60],[3,100]]
z [[0.2,20],[1.5,40],[3,120]]
但这并没有发生! 知道为什么要删除括号以及如何将它们恢复原状吗?
谢谢,
索林
【问题讨论】:
-
[ [ 1 ,2 ] ]在 json 中的类型是Array[Array]而不是Array[String]
标签: json ajax servlets highcharts