AngularJS访问JSON中的值

时间:2015-11-28 07:08:01

标签: angularjs json

您好我有以下JSON

{
    id: 35,
    chain_id: 32,
    name: "HAPS",
    phone: "33330210",
    url: null,
    contact: null,
    user_id: null,
    uuid: null,
    lat: 55.682044,
    lng: 12.572165,
    before_closing_time: 15,
    slug: "haps",
    img_url: {
        img_url: {
            url: "https://stmstd.s3.amazonaws.com/development/location/img_url/35/35_2-d85876cea2d0933c99d99177ddec36e0.png",
            thumb: {
                url: "https://stmstd.s3.amazonaws.com/development/location/img_url/35/thumb_35_2-d85876cea2d0933c99d99177ddec36e0.png"
            },
            big: {
                url: "https://stmstd.s3.amazonaws.com/development/location/img_url/35/big_35_2-d85876cea2d0933c99d99177ddec36e0.png"
            },
            email: {
                url: "https://stmstd.s3.amazonaws.com/development/location/img_url/35/email_35_2-d85876cea2d0933c99d99177ddec36e0.png"
            }
        }
    },
    img_high_url: "/assets/35@2-d70e1305b0681703e0ed19125d2d8a17.png",
    time_zone: "Copenhagen",
    hosted_datas: [{
        id: 10,
        place_id: 35,
        place_type: "Location",
        data: {
            layout_template: "",
            layout_template_view: "",
            header: "VELKOMMEN TIL HAPS",
            sub_header1: "SE MENU OG BESTIL DIREKTE",
            sub_header2: "",
            about_us_header: "Velkommen til HAPS i Fiolstræde",
            about_us: "I 2012 slog HAPS dørene op i Fiolstræde. Vi laver ærlig, sund mad og juice, der er til at betale. Husk at vi også leverer frokost og catering. Kontakt os på 33 33 02 10. ",
            search_suggestion: "salat",
            footer_left_text: "",
            social_media_fallback_header: "",
            social_media_fallback_text: "",
            dk_smiley_link_text: "Se Smiley",
            left_header: "",
            left_content: "",
            left_big_phone: "33 33 02 10",
            url_logo: "haps_stor.png",
            url_small_logo: "Haps_smallestesss.png",
            url_main_image: "haps_baggrund.jpg",
            footer_left_img: "powdbtmini.png",
            google_description: "",
            video_url_top_mp4: ""
        },
        url_logo: "https://stmstd.s3.amazonaws.com/development/hosted_data/url_logo/10/haps_stor.png",
        url_small_logo: "https://stmstd.s3.amazonaws.com/development/hosted_data/url_small_logo/10/Haps_smallestesss.png",
        url_main_image: "https://stmstd.s3.amazonaws.com/development/hosted_data/url_main_image/10/haps_baggrund.jpg",
        footer_left_img: "https://stmstd.s3.amazonaws.com/development/hosted_data/footer_left_img/10/powdbtmini.png",
        url_chainview_img: null,
        chain_view_table_booking_img: null
    }],
    schedules: [{
        id: 70,
        start: "2013-06-17T00:00:00.000+02:00",
        finish: "2027-08-30T14:38:00.000+02:00",
        cron: null,
        mode: "on",
        range: "monday (10:00-20:00), tuesday (10:00-20:00), wednesday (10:00-20:00), thursday (10:00-20:00), friday (10:00-20:00), saturday (10:00-20:00), sunday (12:00-18:00)",
        status: "active",
        priority: null,
        obj_type: "Location",
        obj_id: 35,
        text: "mandag - lørdag (10:00 - 21:00), søndag (12:00 - 18:00)"
    }],
    addresses: [{
        id: 29,
        owner_id: 35,
        owner_type: "Location",
        street: "Fiolstræde 38",
        street2: "",
        city: "København K",
        zip: "1171",
        state: "",
        country: "Denmark",
        status: null,
        lat: null,
        lng: null,
        geocoded_address: null,
        name_door: null,
        door_comments: null,
        full_address: "Fiolstræde 38 , 1171 København K , Denmark"
    }]
}

我想访问地址中的full_address。

此对象称为location

我尝试了{{location.addresses.full_address}},但这不起作用。 同样,{{location.schedule.range}}也无效。

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

location.addresseslocation.schedules都是数组。

试试location.addresses[0].full_address。它应该工作。

答案 1 :(得分:1)

addressesschedules都是数组。每个这些数组中都有一个对象。您需要像这样访问它:

{{location.addresses[0].full_address}}
{{location.schedules[0].range}}

答案 2 :(得分:0)

访问数组元素时缺少数组索引。 您可以通过{{location.addresses[0].full_address}}获取完整地址。 同样,使用{{location.schedules[0].range}}

获取范围