public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
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, title, des;
while ((line = bfr.readLine()) != null) {
JSONArray jsa = new JSONArray(line);
for (int i = 0; i < jsa.length(); i++) {
JSONObject jo = (JSONObject) jsa.get(i);
title = jo.getString("Amount");
countryList.put(i, title);
}
renderRequest.setAttribute("out-string", countryList);
super.doView(renderRequest, renderResponse);
}
} catch (Exception e) {
}
}
我正在嘗試訪問來自liferay portlet類的json
對象,我想將任何json
字段值的數組傳遞給jsp頁面。如何從java客戶端使用JSON Webservice?
您需要閱讀完整的響應,然後將其轉換爲JSONArray。響應中的每一行都將成爲(無效的)JSON片段,並且不能孤立地進行分析。 – Perception