Javascript 我试图从JSON文件检索数据,但从特定属性检索信息时遇到问题

Javascript 我试图从JSON文件检索数据,但从特定属性检索信息时遇到问题,javascript,arrays,angularjs,json,object,Javascript,Arrays,Angularjs,Json,Object,这是我的JSON文件: { "query":{ "count":1, "created":"2016-06-16T21:09:11Z", "lang":"en-US", "results":{ "channel":{ "units":{ "distance":"mi", "pressure"

这是我的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"
                }
            }
        }
    }
}
这不是全部代码,但这是我遇到麻烦的部分


我正在尝试将位置(
Ormond Beach,Fl
)保存为变量。我正在使用angularjs代码,但它似乎不起作用:
$scope.location=response.data.query.results.location。JSON文件没有什么问题,因为我在JSON文件中使用
ng repeat
检索了其他信息,但是,我在将
Ormond Beach
保存为变量
$scope.location
时遇到了问题。请帮帮我


非常感谢

response.data.query.results.location
不是一个字符串,而是一个具有3个属性的对象,每个属性都是字符串:

{
    "city":"Ormond Beach",
    "country":"United States",
    "region":" FL"
}
您需要连接所需的属性:

$scope.location = response.data.query.results.location.city + ', ' + response.data.query.results.location.region;
为了好玩,我将向您展示我喜欢用于这类事情的表单:

$scope.location = [
    response.data.query.results.location.city,
    response.data.query.results.location.region
].join(', ');

它可以帮助我非常清楚地看到哪些数据正在进入。

response.data.query.results.location
不是一个字符串,而是一个具有3个属性的对象,每个属性都是字符串:

{
    "city":"Ormond Beach",
    "country":"United States",
    "region":" FL"
}
您需要连接所需的属性:

$scope.location = response.data.query.results.location.city + ', ' + response.data.query.results.location.region;
为了好玩,我将向您展示我喜欢用于这类事情的表单:

$scope.location = [
    response.data.query.results.location.city,
    response.data.query.results.location.region
].join(', ');

这有助于我非常清楚地看到哪些数据正在进入。在位置和结果之间有一个中间对象,即通道

请尝试:

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

然后你只需要连接location.city和location.region,在location和result之间有一个中间对象,即channel

请尝试:

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

然后您只需要将location.city和location.region连接起来

$scope.location=response.data.query.results.channel.units.location.city+“,“+response.data.query.results.channel.units.location.region
@alereisan我在units.location中没有看到location对象。location是
response.data.query.results.channel.location
$scope.location=response.data.query.results.channel.units.location.city+,“+response.data.query.results.channel.units.location.region@alereisan我在单位内没有看到位置对象。位置是
response.data.query.results.channel.location