0

I am trying to parse the data from JSON format, but i get first alert which is (insdie 1: object Object) and then i don't get the second alert. I am not sure what i did wrong.

JS

$.getJSON("http://localhost:8080/JsoupPrj/JasonGen?url="+url
                    ,function(data){
                var imageData = [];
                alert("inside 1 :" + data);
                $.each(data.items,function(i, item){
                    alert("insdie 2");
                    alert(item);
                    });

JSON DATA

{
  "title" : "x",
  "Description" : "rrr.",
  "images" : [ "http://1.jpg", "http://2.jpg", "http://3.jpg" ]
}
1
  • Is the page loaded from the same domain, i.e. http://localhost:8080? If not you won't be able to access it due to the same-origin policy. Commented Aug 24, 2012 at 21:59

1 Answer 1

1

Your JSON data doesn't have a property called items, so data.items is undefined. Try data.images instead:

$.each(data.images,function(i, item){
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, i just figure it out. How to get only images?
I don't know what you mean. Within the $.each() loop item will be "http://1.jpg" on the first iteration, then "http://2.jpg", etc. Unless you're asking how to populate your imageData variable with those values, in which case you can just say imageData = data.images;. But given imageData is a local variable it's kind of redundant when you can just access data.images directly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.