任何人都可以请帮我理解我应该如何访问js中的json数据。 JSP-struts代码访问。我正在使用struts2,json,dojo。但是让问题访问数据。如何在dojo中使用json数据
var chartData = dojo.xhrGet({
url : "getJSONResult",
handleAs : "json",
preventCache : false,
load : function(data) {
//how to process
}
});
我在struts.xml
<package name="json" namespace="/" extends="json-default">
<action name="getJSONResult" method="execute"
class="uk.co.bandc.businessmonitor.web.controller.ShowTransactionAction">
<result type="json" />
</action>
</package>
我的动作类
package uk.co.bandc.businessmonitor.web.controller;
import com.opensymphony.xwork2.ActionSupport;
public class ShowTransactionAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
int[] numberarray1 = { 10000, 9200, 11811, 12000, 7662, 13887, 14200, 12222, 12000,
10009, 11288, 12099 };
public String execute() {
return SUCCESS;
} // End execute()
public int[] getNumberarray1() {
return numberarray1;
}
public void setNumberarray1(int[] numberarray1) {
this.numberarray1 = numberarray1;
}
} // End class
请修复代码格式,谢谢。 – bernie 2012-03-27 16:39:01
您遇到的问题是什么?你的AJAX回调函数中的数据不包含JSON吗?如果是这样,首先要测试的是,当您使用键入浏览器位置的URL访问您的操作时,是否将JSON数据返回到浏览器中? – 2012-03-27 16:59:47
是的,如果我访问http://127.0.0.1:8080/bizmon-web-user/getJSONResult我得到的结果{“numberarray1”:[10000,9200,11811,12000,7662,13887,14200,12222,12000, 10009,11288,12099]}。我想使用数组中的值作为图表的输入。但不知道该怎么做。 – JavaOyeOye 2012-03-27 17:07:13