我只是好奇,在如何訪問此JSON調用中的任何字段,因爲它有多個對象,是非常困惑,因爲這是我第一次處理這個。這裏是鏈接到JSON: http://api.wunderground.com/api/5ad0204df4bdbeff/forecast/q/Australia/Sydney.json?callback=JSON_CALLBACKJSON AngularJS多個對象
我的代碼使用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="[email protected]" 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」對象,然後訪問溫度區域。我將如何去做這件事?
你在console.log(data)中收到了什麼; ? – Artemis 2014-10-08 09:53:18
對象{response:Object,forecast:Object}但是你可以進一步擴展它 – Indrick 2014-10-08 09:56:35
,這樣你可以通過seceived對象的屬性並最終看到視圖。喜歡weatherData.forecast.somePropertyHere – Artemis 2014-10-08 09:58:15