如何从服务器到Jquery移动应用程序获取JSON数组
我有一个基于REST的Web服务,它返回json数组,如如何从服务器到Jquery移动应用程序获取JSON数组,jquery,rest,jquery-mobile,getjson,Jquery,Rest,Jquery Mobile,Getjson,我有一个基于REST的Web服务,它返回json数组,如 [{“姓名”:“abc”,“年龄”:“24”,“性别”:“女性”}]。我从Jquery移动应用程序中使用了这个Web服务,比如 $.getJSON("http://localhost:8080/webservice/name", { name: +$("name") }, function(resultList){ alert("JSON Data: " + resultList.age); }); 但我的警报框中出现“未
[{“姓名”:“abc”,“年龄”:“24”,“性别”:“女性”}]
。我从Jquery移动应用程序中使用了这个Web服务,比如
$.getJSON("http://localhost:8080/webservice/name", { name: +$("name") }, function(resultList){
alert("JSON Data: " + resultList.age);
});
但我的警报框中出现“未定义”。如何从webservice返回JSON数组。这里可能有什么问题?请尝试一下,看看它是否有效:
$.getJSON("http://localhost:8080/webservice/name", { name: +$("name") }, function(resultList){
$.each(resultList, function(key, val) {
alert("JSON Data: key" + key + " value: " + value);
});
});
resultList
是一个JSON对象数组,它将/可以包含多个JSON对象。因此,尝试resultList.age
是行不通的——在获取其age
属性之前,需要访问resultList
中的特定索引。更多信息,请参见Aziz的答案。