JSON AngularJS多个对象
JSON AngularJS multiple objects
我只是好奇如何访问这个JSON调用中的任何字段,因为它有多个对象,非常令人困惑,因为这是我第一次处理这个问题。以下是指向JSON的链接:http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Sydney.json?callback=JSON_CALLBACK
我的代码使用AngularJS调用JSON并存储它。然后绑定值通过循环访问它。
<!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>
本质上,我想访问"simpleforecast"对象,然后访问温度区域。我该怎么做?
它一定是这样的:
<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>
我建议使用一些JSON查看器/格式化程序工具来从复杂的JSON中找到您想要的数据。事实上,我是用这个工具找到的。
获得今天的低温和高温
data.forecast.simpleforecast.forecastday[0].high.celsius
data.forecast.simpleforecast.forecastday[0].low.celsius
此外,该服务还提供4天的天气预报,如果您想让他们更改天气预报日的指数。0是今天,1是明天,依此类推。
<li ng-repeat="weather in weatherData.forecast.forecast.simpleforecast">
{{weather.forecastday[0].high.celsius}}
{{weather.forecastday[0].low.celsius}}
</li>
相关文章:
- AngularJs指令,该指令创建内部有数据对象的新指令
- AngularJS&JSON-从Previous&下一个对象
- 遍历AngularJs中的对象
- Angularjs:空对象,当只有一次点击时
- Javascript/AngularJs-如何用另一个数组中的对象填充数组
- AngularJS:如何用同一对象的另一个属性访问一个属性
- 在禁用ng的情况下搜索JSON对象(AngularJS)
- 将数据推送到对象angularjs
- 将第二个或多个数组推送到数组对象 AngularJS 中
- 用于对象AngularJs中包含的所有字段和数组的deepCopy
- 对于返回 1 个对象 Angularjs
- 使用内部数组遍历数组并创建新对象 - AngularJS
- 向json对象angularjs添加一个数组
- 如何删除数组中使用过滤器的对象?AngularJS
- 如何将密钥分配给对象Angularjs
- 将数据推送到对象AngularJS中
- 在导入的JSON对象AngularJS中获取一个数组
- 返回$rootScope函数中的对象(AngularJS)
- 如何遍历这个 Json 对象(angularJS)
- 按属性排序数组中的javascript对象(angularjs过滤器)