2017-06-27 29 views
0

我正在研究一個簡單的應用程序,我可以使用它調用(使用REST服務)Open Weather Map(OWM)服務來接收JSON輸出並使用它執行各種操作。我在Eclipse中使用Spring MVC框架,我可以得到一個JSON輸出,但是我得到的所有東西都是NULL。我覺得這與OWM沒有從我調用它的方式來識別我的API密鑰有關。任何指針都會很棒。我也使用OWM網站上解決方案和parters部分提供的OWM java庫。使用Spring MVC打開天氣圖

@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響應我覺得,如果我能得到的溫度什麼不合理。任何指針將非常感激!

回答

0

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