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) {
}
}
I am trying to access json
object from liferay portlet class and I want to pass an array of values of any json
field to the jsp page.
You need to read the full response before converting it into a JSON array. This is because each individual line in the response is going to be an (invalid) JSON fragment, which cannot be parsed in isolation. With slight modifications your code should work, highlights below: