0
我已經經歷了幾篇文章,並且仍然無法訪問嵌套的對象數據。我使用的是工廠使用JSONP獲取天氣信息:在數組中訪問嵌套的json數據角度
this.testApi = function(coords) {
var deferred = $q.defer();
$http.jsonp(API_ROOTS + '?key=khjsgf7bhv3y3hy776763&q=' + coords.latitude + ',' + coords.longitude + '&cc=yes&includeLocation=yes&format=json&callback=JSON_CALLBACK')
.then(function(response) {
deferred.resolve(response.data);
console.log(response.data.data);
}, function(error) {
deferred.reject(error);
}
);
return deferred.promise;
};
這將返回看起來像這樣的迴應:
Object {current_condition: Array[1], nearest_area: Array[1], request: Array[1], weather: Array[5]}
現在裏面,可以說,current_condition,它看起來像這樣:
0: Object
FeelsLikeC: "17"
FeelsLikeF: "63"
cloudcover: "0"
humidity: "23"
observation_time: "09:51 AM"
precipMM: "0.0"
pressure: "1028"
temp_C: "17"
temp_F: "63"
visibility: "10"
weatherCode: "113"
weatherDesc: Array[1]
weatherIconUrl: Array[1]
winddir16Point: "WSW"
winddirDegree: "250"
windspeedKmph: "7"
windspeedMiles: "4"
__proto__: Object
length: 1
__proto__: Array[0]
唯一的問題是,當我嘗試在我的HTML訪問它我沒有得到任何出來的說:
{{place.current_condition.FeelsLikeC}}
似乎並不輸出任何東西......
{{places [0] .current_condition.FeelsLikeC}}如果地點是列表 – Hmahwish
是否放置對象? – Hmahwish
哎對不起,是的地方是一個對象。打印錯誤。這裏是我得到的完整的JSON輸出:[鏈接] http://plnkr.co/edit/oyNboaZm0BtamnjuDypx?p=catalogue [/鏈接]如果,在我的工廠我輸出'deferred.resolve(response.data.data );'我得到了plunkr中的json輸出 – letterman549