Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从服务器到Jquery移动应用程序获取JSON数组_Jquery_Rest_Jquery Mobile_Getjson - Fatal编程技术网

如何从服务器到Jquery移动应用程序获取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); }); 但我的警报框中出现“未

我有一个基于REST的Web服务,它返回json数组,如
[{“姓名”:“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的答案。