Javascript JSON AngularJS多个对象
我只是好奇如何访问这个JSON调用中的任何字段,因为它有多个对象,而且非常混乱,因为这是我第一次处理这个问题。以下是指向JSON的链接: 我的代码使用AngularJS调用JSON,然后存储它。然后通过循环访问绑定值Javascript JSON AngularJS多个对象,javascript,json,angularjs,Javascript,Json,Angularjs,我只是好奇如何访问这个JSON调用中的任何字段,因为它有多个对象,而且非常混乱,因为这是我第一次处理这个问题。以下是指向JSON的链接: 我的代码使用AngularJS调用JSON,然后存储它。然后通过循环访问绑定值 <!DOCTYPE html> <html ng-app="plunker"> <head> <meta charset="utf-8" /> <title>AngularJS Plunker<
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<script data-require="angular.js@1.2.x" src="https://code.angularjs.org/1.2.25/angular.js" data-semver="1.2.25"></script>
<script >
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $http) {
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Sydney.json?callback=JSON_CALLBACK').success(function(data){
console.log(data);
$scope.weatherData=data;
})
});
</script>
</head>
<body ng-controller="MainCtrl">
<ul>
<li ng-repeat="weather in weatherData">
{{weather.celsius}}
</li>
</ul>
</body>
</html>
安古拉斯普朗克
文件。写(“”);
var app=angular.module('plunker',[]);
app.controller('MainCtrl',函数($scope,$http){
$http.jsonp('http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Sydney.json?callback=JSON_CALLBACK)。成功(函数(数据){
控制台日志(数据);
$scope.weatherData=数据;
})
});
-
{{天气.摄氏度}
基本上,我想访问“simpleforecast”对象,然后访问温度区域。我该怎么做呢?编辑:我为您制作了一把小提琴来演示ng repeat的用法。这里是 一定是这样的:
<ul>
<li ng-repeat="forecast in weatherData.forecast.simpleforecast.forecastday">
<br/>date: {{forecast.date.pretty}}
<br/>high: {{forecast.high.celsius}},
<br/>low: {{forecast.low.celsius}}
</li>
</ul>
此外,服务还提供4天的天气预报,如果您希望他们更改天气预报日的指数。0是今天,1是明天,依此类推。<li ng-repeat="weather in weatherData.forecast.forecast.simpleforecast">
{{weather.forecastday[0].high.celsius}}
{{weather.forecastday[0].low.celsius}}
</li>
{{weather.forecastday[0].high.cercific}
{{weather.forecastday[0].低温}
您在console.log(数据)中接收到什么?对象{response:Object,forecast:Object}但是您可以进一步扩展它,这样您就可以浏览seceived对象中的属性,最后在视图中查看。像weatherData.forecast.SomeProperty基本上你可以一直查看到它,但是我要把它放在{{}界限值区域吗?你可以使用weatherData.forecast.forecast.simpleforecast访问“simpleforecast”对象来尝试{{weather.forecastday[0]。high.celsius}}更正了以摄氏为单位的打字错误。还添加了一个工作提琴来演示ng-repeat的用法。啊,好的,我知道在测试它时我做错了什么,我把weatherData.forecast.simpleforecast.forecastday放在{{}
<li ng-repeat="weather in weatherData.forecast.forecast.simpleforecast">
{{weather.forecastday[0].high.celsius}}
{{weather.forecastday[0].low.celsius}}
</li>