Map countryList = new HashMap();
String str = "http://10.10.10.25/TEPortalIntegration/CustomerPortalAppIntegrationService.svc/PaymentSchedule/PEPL/Unit336";
try {
URL url = new URL(str);
URLConnection urlc = url.openConnection();
BufferedReader bfr = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String line, des;
double title;
final StringBuilder builder = new StringBuilder(2048);
while ((line = bfr.readLine()) != null) {
builder.append(line);
}
// convert response to JSON array
final JSONArray jsa = new JSONArray(builder.toString());
// extract out data of interest
for (int i = 0; i < jsa.length(); i++) {
final JSONObject jo = (JSONObject) jsa.get(i);
title = jo.getDouble("NetAmount");
countryList.put(i, title);
}
System.out.println(countryList); /* Giving result if i run in Console*/
} catch (Exception e) {
// TODO: handle exception
}
renderRequest.setAttribute("out-string", countryList);
上面的代碼是從java客戶端使用JSON Web服務。我可以從Java控制檯應用程序訪問它。但是,在嘗試使用JSP或Liferay時,它不起作用。在JSP中,它給出java.lang.NoClassDefFoundError:org/json/JSONArray。請幫我解決它。 我是否需要將更多jar文件添加到庫中以使其在JSP中工作?爲什麼JSONArray從JSP中拋出ClassNotFound異常?
你能告訴我需要包含哪些jar文件嗎?你能給我下載鏈接嗎? – Shibu
只要到這個網站,搜索你就會知道哪些圖書館有這個類:http://www.findjar.com – Abubakkar