2011-07-08 41 views
0

我有一個基於REST的webservice,它返回像 [{"name":"abc","age":"24","gender":"female"}]這樣的json數組。我用這個Web服務從我的jQuery Mobile的應用程序一樣如何從服務器獲取JSON數組到Jquery移動應用程序

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

但我在我的提示框變得「不確定」。如何從webservice返回JSON數組。這裏可能是什麼問題?

+0

'resultList'是JSON對象的數組,它將/可包含多個JSON對象。所以嘗試'resultList.age'永遠不會起作用 - 在獲取'age'屬性之前,您需要訪問'resultList'中的特定索引。查看來自Aziz的更多答案。 – Ben

回答

1

請試試這個,看看它的工作原理:

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