簡體   English   中英

使用Spring MVC打開天氣圖

[英]Open Weather Map using Spring MVC

我正在開發一個簡單的應用程序,該應用程序可用於調用(使用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響應,我會感覺好像可以輕松獲得溫度,而無法輕松獲得。 任何指針將不勝感激!

我意識到由於工作中的防火牆,我返回了一個空值。 關閉代理,一切正常!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM