这里我使用的是Struts2框架。我正在尝试获取JSONArray
数据,如
jSONArray.add("[[4.4,7.0,3.3,6.2,1.3,1.7,],[4.9,6.7,1.1,3.3,4.4,6.1,],
[5.4,6.9,4.8,5.2,4.9,6.8,],[0.0,0.0,0.0,0.0,0.0,0.0,],
[0.0,0.0,0.0,0.0,0.0,0.0,],[0.0,0.0,0.0,0.0,0.0,0.0,],]");
这是6 X 6阵列数据,我正在尝试使用Ajax打印此数据,但我得到这样的输出 4.4,7,3.3,6.2,1.3,1.7,4.9,6.7,1.1,3.3,4.4,6.1,5.4,6.9,4.8,5.2,4.9,6.8 ,,, 我需要输出为 4.4,7,3.3,6.2,1.3,1.7,4.9,6.7,1.1,3.3,4.4,6.1,5.4,6.9,4.8,5.2,4.9,6.8,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0。 我没有得到零值。如果我使用6 X 5阵列数据,那么它完全正常工作。
动作:
public class JsonAction extends ActionSupport{
public String jasonRequest(){
jSONObject=new JSONObject();
jSONArray=new JSONArray();
jSONArray.add("[[4.4,7.0,3.3,6.2,1.3,1.7,],[4.9,6.7,1.1,3.3,4.4,6.1,],
[5.4,6.9,4.8,5.2,4.9,6.8,],[0.0,0.0,0.0,0.0,0.0,0.0,],
[0.0,0.0,0.0,0.0,0.0,0.0,],[0.0,0.0,0.0,0.0,0.0,0.0,],]");
jSONObject.put("status", jSONArray);
System.out.println("json result "+jSONObject.get("status").toString());
return SUCCESS;
}
}
页:
<Html>
<head>
<script>
function abc(){
var vals1='hai';
$.ajax({
url: "JsonAction.action",
method: "POST",
data: 't1='+vals1,
dataType: "json",
success:function(result){
document.getElementById("name0").innerHTML=result.status[0];
}
})
}
</script>
</head>
<body>
<input type="submit" name="b1" value="add" onclick="abc()"/>
<div id="name0"> </div>
</body>
</Html>