这是我的 JSON 文件:
{
"query":{
"count":1,
"created":"2016-06-16T21:09:11Z",
"lang":"en-US",
"results":{
"channel":{
"units":{
"distance":"mi",
"pressure":"in",
"speed":"mph",
"temperature":"F"
},
"title":"Yahoo! Weather - Ormond Beach, FL, US",
"link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2466336/",
"description":"Yahoo! Weather for Ormond Beach, FL, US",
"language":"en-us",
"lastBuildDate":"Thu, 16 Jun 2016 05:09 PM EDT",
"ttl":"60",
"location":{
"city":"Ormond Beach",
"country":"United States",
"region":" FL"
}
}
}
}
}
这不是全部代码,但这是我遇到问题的部分。
我正在尝试将位置(佛罗里达州奥蒙德海滩
)保存为变量。我正在使用这个 angularjs 代码,但它似乎不起作用:$scope.location = response.data.query.results.location;
。 JSON 文件没有任何问题,因为我稍后使用 ng-repeat
在 JSON 文件中检索了其他信息,但是,我在将 Ormond Beach
保存为变量$scope.location
。请帮我!
非常感谢!
最佳答案
位置和结果之间有一个中间对象,即 channel 。
尝试一下:
$scope.location = response.data.query.results.channel.location;
然后你只需要连接location.city和location.region
关于javascript - 我正在尝试从 JSON 文件检索数据,但在从特定属性检索信息时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869907/