【问题标题】:How to Parse a complex Json into an Array using Angular/Jquery or javascript? [closed]如何使用 Angular/Jquery 或 javascript 将复杂的 Json 解析为数组? [关闭]
【发布时间】:2015-04-18 18:44:33
【问题描述】:

您好,我有一个来自 $resource 请求的 json 数据,我需要将其解析为数组,以便遍历其属性。任何帮助将不胜感激。

{
"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"
    }
}

}

我需要填充标签和网址

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

});

谢谢

【问题讨论】:

标签: javascript jquery json angularjs angularjs-ng-repeat


【解决方案1】:

您可以使用 javascripts JSON.parse() 方法将您的 JSON 解析为一个对象。然后你可以遍历对象的键。

var object = JSON.parse(json);

var item;
for (var i in object) {
    item = object[i];
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-09
  • 2012-06-22
  • 2016-11-29
  • 1970-01-01
相关资源
最近更新 更多