0

I have a REST based webservice which returns json array like [{"name":"abc","age":"24","gender":"female"}]. I used this webservice from my Jquery Mobile application like

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

But I am getting "undefined" in my alert box. How to return the JSON Array from webservice. What could be the issue here?

1
  • resultList is an array of JSON objects, it will / can contain more than one JSON object. So attempting resultList.age is never going to work--you need to access a specific index within resultList before grabbing its age attribute. See the answer from Aziz for more. Commented Jul 8, 2011 at 12:24

1 Answer 1

1

Please try this and see if it works:

$.getJSON("http://localhost:8080/webservice/name", { name: +$("name") }, function(resultList){
     $.each(resultList, function(key, val) {
          alert("JSON Data: key" + key + " value: " + value);
     });
}); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.