【问题标题】:How to get the JSON array from server to Jquery mobile application如何从服务器获取 JSON 数组到 Jquery 移动应用程序
【发布时间】: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


【解决方案1】:

请尝试一下,看看它是否有效:

$.getJSON("http://localhost:8080/webservice/name", { name: +$("name") }, function(resultList){
     $.each(resultList, function(key, val) {
          alert("JSON Data: key" + key + " value: " + value);
     });
}); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多