Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question

put on hold as unclear what you're asking by Pointy, pankajparkar, rene, Dustin, Michael Benford 19 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

    
I believe you can just do JSON.parse(object) –  Abdul Ahmad 20 hours ago
    
would you show me an example? –  user1429595 20 hours ago
    
1  
What did you try ? We can "help" you, not code for you . –  Tchi Yuan 20 hours ago
    
Please see jsfiddle.net/maxfar123/NJMyD/3159 –  user1429595 20 hours ago

1 Answer 1

up vote 0 down vote accepted

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];
}
share|improve this answer
    
please see jsfiddle.net/maxfar123/NJMyD/3159 –  user1429595 20 hours ago
    
I've added lots of comments: jsfiddle.net/NJMyD/3161 –  Norman Breau 19 hours ago
    
Thanks Norman, you are the man –  user1429595 19 hours ago
    
Glad I could help! –  Norman Breau 19 hours ago
    
one last favor, would you tell me how I can loop through them as well, like generate both summaries? I truly appreciate it –  user1429595 19 hours ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.