0
我已經創建了一個類,提供了一種方法通過REST以獲得應然後deserialised作爲LinkedHashMap的JSON對象。方法如下:FileNotFoundException異常與ObjectMapper在JSON/REST
@Override
public LinkedHashMap refreshStatus(String metricType, String metricPeriod) {
ObjectMapper mapper = new ObjectMapper();
LinkedHashMap<String,String> map = null;
try {
map = mapper.readValue(new File("http://localhost:8081/Metrics/Stats/JSONP/ReceiveData/"+metricType+"/"+metricPeriod+"/?callback="), LinkedHashMap.class);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return map;
}
當我在瀏覽器中輸入一些特定參數的URL,即
http://localhost:8081/Metrics/Stats/JSONP/ReceiveData/Totals/All/?callback=
我得到一個正確的JSON對象:
{"Boxes":"8","Contracts":"23","Updates":"1","Deactivations":"4","ActiveBoxes":"33","InactiveBoxes":"1","PendingInstallationsContracts":"70","Alerts":"626","PercentsBoxInstalled":"100.0%","Miles":"0"}
然而,當我運行應用程序並調用該方法,我得到一個FileNotFoudException:
java.io.FileNotFoundException: http:/localhost:8081/Metrics/Stats/JSONP/ReceiveData/Totals/All/?callback= (No such file or directory)
有誰知道問題出在哪裏?提前致謝!
有沒有這樣的方法readValueconn .. – Anto