0

Im trying to learn how to get data from json-data but I cannot figure out how to get the 'title' and 'url' when the json looks like this:

{
"about": "about",
"episodes": [
    {
        "id": 123,
        "title": "the title",
        "pod": {
            "podtitle": "podtitle",
            "url": "url"
        }
    },
    {
        "id": 1234,
        "title": "the title2",
        "pod": {
            "podtitle": "podtitle2",
            "url": "url2"
        }

I am using $.getJSON(jsonURL, function(data) { ... but I am just getting the "top" keys.

How do I get the deeper stuff like 'url' and 'podtitle'?

4

2 回答 2

0
data.episodes[someIndex].pod.podtitle

您可能希望以某种方式迭代剧集,要么使用良好的 ol'for循环,要么使用$.each例如。

于 2013-05-03T21:54:09.443 回答
0

episodes有一个数组的值,所以它有数字索引:

data.episodes[0].title;
data.episodes[0].pod.url;
data.episodes.forEach(function (elem) {
    elem.title;
});

我还创建了它,因此您可以将鼠标悬停在元素值上以查看如何使用 JS 访问它们:http: //jsfiddle.net/ExplosionPIlls/yHj5X/1/

于 2013-05-03T21:59:53.010 回答