也是网上搜半天没搜到,最后自己整出来了
js部分:
$.ajax({
dataType : "json",
type : "POST",
url : "getPathMap",
success : function(data) {
var points = eval(data);
alert(points[1][0]+points[1][1]);
},
error : function(e, type, msg) {
alert(type + "===" + msg);
}
});
java部分:
public String getPathMap(HttpServletRequest request, HttpServletResponse response) {
PointsInfo pointsInfo = new PointsInfo();
try {
/*** 根据条件取值生成二维数据,并转成json ***/
// JSONArray jsonArray =
// JSONArray.fromObject(pointsInfo.getPointLine(" or id < '20' "));
String[][] aaa = { { "xxxx", "oooo" }, { "fu", "ck" } };
JSONArray jsonArray = JSONArray.fromObject(aaa);
response.setContentType("text/html;charset=UTF-8");
response.setContentType("application/json");
PrintWriter pw = response.getWriter();
pw.print(jsonArray); // 轨迹图条件,取少量数据
pw.flush();
pw.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
}
测试效果: