-3

Hi I have a json data that comes from $resource request and i need to parse it into array so I could iterate through its properties. any help would be appreciated.

{
"feed": {
    "author": {
        "name": {
            "label": "iTunes Store"
        },
        "uri": {
            "label": "http://www.apple.com/itunes/"
        }
    },
    "entry": [
        {
            "im:name": {
                "label": "Paddington"
            }, 
            "im:image": [
                {
                    "label": "url1",
                    "attributes": {
                        "height": "60"
                    }
                },
                {
                    "label": "url2",
                    "attributes": {
                        "height": "60"
                    }
                },
                {
                    "label": "url3",
                    "attributes": {
                        "height": "170"
                    }
                }
            ]
        },
        {
            "im:name": {
                "label": "Interstellar"
            },"im:image": [
                {
                    "label": "url4",
                    "attributes": {
                        "height": "60"
                    }
                },
                {
                    "label": "url5",
                    "attributes": {
                        "height": "60"
                    }
                },
                {
                    "label": "url6",
                    "attributes": {
                        "height": "170"
                    }
                }
            ]
        }
    ],
    "updated": {
        "label": "2015-04-18T11:29:36-07:00"
    },
    "rights": {
        "label": "Copyright 2008 Apple Inc."
    },
    "title": {
        "label": "iTunes Store: Top Movies"
    }
}

}

I need to populate the labels and the Urls

app.factory('movieService',function ($resource) {
return $resource('https://itunes.apple.com/us/rss/topmovies/limit=50/genre=:id/json', {id: '@id'});

});

Thanks

6
  • I believe you can just do JSON.parse(object) Commented Apr 18, 2015 at 18:46
  • would you show me an example? Commented Apr 18, 2015 at 18:48
  • refer here stackoverflow.com/questions/29712507/… Commented Apr 18, 2015 at 18:48
  • 1
    What did you try ? We can "help" you, not code for you . Commented Apr 18, 2015 at 18:48
  • Please see jsfiddle.net/maxfar123/NJMyD/3159 Commented Apr 18, 2015 at 18:57

1 Answer 1

0

You can use javascripts JSON.parse() method to parse your JSON into an object. Then you can iterate through the object's keys.

var object = JSON.parse(json);

var item;
for (var i in object) {
    item = object[i];
}
Sign up to request clarification or add additional context in comments.

6 Comments

I've added lots of comments: jsfiddle.net/NJMyD/3161
Thanks Norman, you are the man
one last favor, would you tell me how I can loop through them as well, like generate both summaries? I truly appreciate it
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.