Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从WundergroundAPI访问json数据?_Javascript_Json_Api - Fatal编程技术网

Javascript 从WundergroundAPI访问json数据?

Javascript 从WundergroundAPI访问json数据?,javascript,json,api,Javascript,Json,Api,我下面有一个异步函数,它可以访问天气API,我只想从API中检索两条信息:F&C中的温度。我删除了API_键,但如果需要,可以在站点上免费获取一条 由于我的console.log(response)语句,我可以确认我正在接收json对象,但我不确定如何以这种高度嵌入的json符号访问这些数据点 我想我的问题是,如果我想访问城市全名的话,我想我应该做一些类似于response.observation\u location.full的事情,但这不起作用 帮忙 以下是响应json的部分输出: {

我下面有一个异步函数,它可以访问天气API,我只想从API中检索两条信息:F&C中的温度。我删除了API_键,但如果需要,可以在站点上免费获取一条

由于我的console.log(response)语句,我可以确认我正在接收json对象,但我不确定如何以这种高度嵌入的json符号访问这些数据点

我想我的问题是,如果我想访问城市全名的话,我想我应该做一些类似于response.observation\u location.full的事情,但这不起作用

帮忙

以下是响应json的部分输出:

{
    "response": {
        "version": "0.1",
        "termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
        "features": {
            "conditions": 1
        }
    },
    "current_observation": {
        "image": {
            "url": "http://icons.wxug.com/graphics/wu2/logo_130x80.png",
            "title": "Weather Underground",
            "link": "http://www.wunderground.com"
        },
        "display_location": {
            "full": "San Francisco, CA",
            "city": "San Francisco",
            "state": "CA",
            "state_name": "California",
            "country": "US",
            "country_iso3166": "US",
            "zip": "94102",
            "magic": "1",
            "wmo": "99999",
            "latitude": "37.77999878",
            "longitude": "-122.41999817",
            "elevation": "60.0"
        },
        "observation_location": {
            "full": "SOMA, San Francisco, California",
            "city": "SOMA, San Francisco",
            "state": "California",
            "country": "US",
            "country_iso3166": "US",
            "latitude": "37.778488",
            "longitude": "-122.408005",
            "elevation": "23 ft"
        },

我尝试过执行
console.log(response[“current_observation”])
只是为了访问嵌套的数据值,但这似乎不起作用,因为它返回未定义的值。

好的,我解决了我自己的问题,但记录如下:

需要通过resonse.json()将响应转换为json

然后我可以按预期访问属性

this.weather = await response.json();
console.log(this.weather["current_observation"]["temp_f"]);
console.log(this.weather["current_observation"]["temp_c"]);

您收到的响应是什么?与本页上的示例几乎相同
this.weather = await response.json();
console.log(this.weather["current_observation"]["temp_f"]);
console.log(this.weather["current_observation"]["temp_c"]);