Javascript 无法从JSONArray对象获取值,我只需要forEach、ItemFileReadStore、JSON.parse
嗨 我从数据库中获取值并将值放入JSONObject中 像 之后,将JSONObject放入JSONArray并将响应发送回jsp页面 在JSP中:Javascript 无法从JSONArray对象获取值,我只需要forEach、ItemFileReadStore、JSON.parse,javascript,json,Javascript,Json,嗨 我从数据库中获取值并将值放入JSONObject中 像 之后,将JSONObject放入JSONArray并将响应发送回jsp页面 在JSP中: dojo.xhrGet( { url : "/POC/Action.do", handleAs : "json", sync: true, load : function(response, ioArgs) { alert("re
dojo.xhrGet( {
url : "/POC/Action.do",
handleAs : "json",
sync: true,
load : function(response, ioArgs) {
alert("retrived response ------"+response);
//Here i need to fetch only the values like {17,19,21,23,24,27} not the key from response.. but i am unable to fetch it
return response;
},
error: function(response, ioArgs){
dojo.byId("grid").innerHTML = "An error occurred, with response: " + response; return response;
},
handleAs: "json"
});
只需要从响应中获取像{17,19,21,23,24,27}这样的值,而不是键。。但是我拿不到它。我只是forEach,ItemFileReadStore,JSON.parse,但无法。。如果您从web服务器(您可以使用fiddler等进行检查)收到以下数据,请提供帮助:
[{"JAN":"17"},{"FEB":"19"},{"MAR":"21"},{"APR":"23"},{"MAY":"24"},{"JUN":"27"}]
然后,您可以在响应处理程序中执行以下操作:
var output = [];
for(var i in response)
for(var x in response[i])
output.push(response[i][x]);
输出数组将具有所需的所有值
var output = [];
for(var i in response)
for(var x in response[i])
output.push(response[i][x]);