嗨,
我正在从数据库中获取值并将值放入 JSONObject 中 喜欢
[{"JAN":"17"},{"FEB":"19"},{"MAR":"21"},{"APR":"23"},{"MAY":"24"},{"JUN":"27"}]
之后将 JSONObject 放入 JSONArray 并将响应发送回 jsp 页面。
在 JSP 中:
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 但无法..请帮助
最佳答案
如果您来自网络服务器的响应(您可以使用 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]);
输出数组将包含您需要的所有值
关于javascript - 无法从 JSONArray 对象获取值,我只是 forEach 、 ItemFileReadStore、JSON.parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840524/