【发布时间】:2011-07-08 20:23:52
【问题描述】:
我有一个基于 REST 的 web 服务,它返回 json 数组,如
[{"name":"abc","age":"24","gender":"female"}]。我从我的 Jquery Mobile 应用程序中使用了这个网络服务,比如
$.getJSON("http://localhost:8080/webservice/name", { name: +$("name") }, function(resultList){
alert("JSON Data: " + resultList.age);
});
但我的警报框中出现“未定义”。如何从 web 服务返回 JSON 数组。这可能是什么问题?
【问题讨论】:
-
resultList是一个 JSON 对象数组,它将/可以包含多个 JSON 对象。所以尝试resultList.age永远不会奏效——您需要在获取age属性之前访问resultList中的特定索引。有关更多信息,请参阅 Aziz 的答案。
标签: jquery rest jquery-mobile getjson