[英]Can't Access individual JSON data [AngularJS]
I have an external JSON file hotel.json. 我有一个外部JSON文件hotel.json。
{
"hotel_info": [{
"booking_id": "2",
"hotel_name": "Ascot Lodging",
"star_id": "2",
"street": "Via Vincenzo da Seregno",
"province": "Milan",
"price_per_night": "417.00"
}]
}
I'm using AngularJS to read this and display the data. 我正在使用AngularJS读取并显示数据。 In my controller I have:
在我的控制器中,我有:
app.controller('mainController', function($scope,$http) {
$http.get('includes/hotel.json').success(function (data) {
$scope.hotel = data;
});
});
I should then be able to display the data on the HTML page using: 然后,我应该能够使用以下命令在HTML页面上显示数据:
<h3>{{ hotel.hotel_info.hotel_name }}</h3>
This should display " Ascot Lodging " but it doesn't display anything. 这应该显示“ Ascot Lodging ”,但不显示任何内容。
The data is being passed through because if I remove .hotel_name from the handlebars it simply returns the whole JSON text. 数据正在传递,因为如果我从车把中删除.hotel_name,它只会返回整个JSON文本。
Does anyone know why I can't access the individual information? 有谁知道我为什么无法访问个人信息?
Thank you in advance. 先感谢您。
In your JSON hotel_info
is an array not an object (the square brackets []
are the array notation). 在您的JSON中,
hotel_info
是不是对象的数组(方括号[]
是数组表示法)。 Change to: 改成:
<h3>{{ hotel.hotel_info[0].hotel_name }}</h3>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.