无法使用jQuery $ .getJSON在JSON数组中读取JSON数组

时间:2016-08-26 13:04:43

标签: javascript jquery arrays json getjson

我无法在JSON对象中获取JSON数组的项目。这是我的JSON的样子:

[
{
    "category":9,
    "channels":[
        {
            "id":5,
            "title":"MYTITLE",
            "active":true,
            "recent":true,
            "image":"/arts/736c1ad4-2dbe-40a6-859d-8dba89c26ec2.jpg",
            "recent_tracks":{
                "vip":"https://api.xyzsite.com/recent_tracks/vip-3.json",
                "free":"https://api.xyzsite.com/recent_tracks/free-3.json"
            },
            "additional_vip_channels":[
                {
                    "channel_name":"vip-3a",
                    "recent_tracks_uri":"https://api.xyzsite.com/recent_tracks/vip-3a.json",
                    "streams":{
                        "320":"http://streams.xyzsite.com/api/914/320/stream",
                        "64":"http://streams.xyzsite.com/api/914/64/stream",
                        "192":"http://streams.xyzsite.com/api/914/192/stream"
                    }
                }
            ],
            "streams":{
                "free":"http://streams.xyzsite.com/api/31/56/stream",
                "free_56":"http://streams.xyzsite.com/api/31/56/stream",
                "free_128":"http://streams.xyzsite.com/api/31/128/stream",
                "320":"http://streams.xyzsite.com/api/33/320/stream",
                "64":"http://streams.xyzsite.com/api/33/64/stream",
                "192":"http://streams.xyzsite.com/api/33/192/stream"
            }
        },

我使用以下代码来获取值:

$.getJSON('https://api.xyzsite.com/channels.json', function(response) {
            $.each(response, function (index, value) {
                var catId = value.category;
                $.each(value.channels, function (index, value) {                        
                    XYZApp.channels.push({
                        categoryId: catId,
                        id: value.id,
                        name: value.title,
                        image: value.image,
                        recent_tracks: {
                            vip: value.recent_tracks.vip,
                            free: value.recent_tracks.free
                        },
                        streams: {
                            free_128: value.streams.free_128,
                            member_320: value.streams["320"],
                            member_64: value.streams["64"],
                            member_192: value.streams["192"]
                        }
                    });

                    console.log(value.additional_vip_channels);

                });

            });
        }).
then ...

我可以获取值,但是我无法在.each jQuery函数中读取additional_vip_channels数组。我已经尝试过了:

  • value.additional_vip_channels.channel_name
  • value.additional_vip_channels [0] .channel_name
  • value.additional_vip_channels [ “0”]。CHANNEL_NAME

但它们都不起作用。

日志输出也在这里:

enter image description here

如何在additional_vip_channels中获取channel_name和其他数据?

1 个答案:

答案 0 :(得分:1)

我相信你会想要:

adb connect ipadress

同样,这应该有效:(只是一种不同的选择方式)

channels[0]['additional_vip_channels'][0]['channel_name']

希望有所帮助和工作:)