Matt Matt - 5 months ago 10
AngularJS Question

I am trying to retrieve data from a JSON file, but I am having trouble retrieving information from a specific property

Here is my JSON file:

{
"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"
}
}
}
}
}


This is not all of the code, but it is the part that I am having trouble with.

I am trying to save the location (
Ormond Beach, Fl
) as a variable. I am using this angularjs code and it doesn't seem to work:
$scope.location = response.data.query.results.location;
. There is nothing wrong with the JSON file, as I have retrieved other information much later in the JSON file using
ng-repeat
, but, I am having trouble saving
Ormond Beach
as the variable
$scope.location
. Please help me!

Thanks so much!

gyc gyc
Answer

There's an intermediate object between location and result which is channel.

Try instead:

$scope.location = response.data.query.results.channel.location;

Then you just need to concatenate location.city and location.region

Comments