【问题标题】:Open Weather Map using Spring MVC使用 Spring MVC 打开天气图
【发布时间】:2017-06-27 12:52:57
【问题描述】:

我正在开发一个简单的应用程序,我可以使用它来调用(使用 REST 服务)开放天气图 (OWM) 服务来接收 JSON 输出并用它做各种事情。我在 Eclipse 中使用 Spring MVC 框架,我能够获得 JSON 输出,但我得到的所有内容都显示为 NULL。我觉得这与 OWM 没有从我调用它的方式识别我的 API 密钥有关。任何指针都会很棒。我还在使用 OWM 网站上的解决方案和合作伙伴部分提供的 OWM java 库。

    @GetMapping(value = "/current/{city}")
    public ResponseEntity currentWeather(@PathVariable("city") String city) throws MalformedURLException, JSONException, IOException{
    //String apiKey = "**myAPIKey**";
    OpenWeatherMap openWMap = new OpenWeatherMap("**myAPIKey**");
    openWMap.getApiKey();
    CurrentWeather currentW = openWMap.currentWeatherByCityName("Berlin");

    return new ResponseEntity(currentW, HttpStatus.OK);
}

}

我的输出看起来像

{

"responseCode": -2147483648,
"rawResponse": null,
"dateTime": null,
"weatherCount": 0,
"cityName": null,
"coordInstance": null,
"mainInstance": null,
"rainInstance": null,
"sysInstance": null,
"windInstance": null,
"baseStation": null,
"cityCode": -9223372036854775808,
"cloudsInstance": null,
"valid": false

}

如果我能弄清楚如何获得正确的 JSON 响应,我会觉得我可以很容易地获得温度和其他什么。任何指针将不胜感激!

【问题讨论】:

    标签: java json spring spring-mvc


    【解决方案1】:

    我意识到由于工作中的防火墙,我返回了一个空值。关闭代理,一切正常!

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      相关资源
      最近更新 更多