I am crating a json array of dynamic length in my BO class and passing that array to the controller.from controller I have send that array to the jsp successfully using expression language.now I am getting an exception on my for each loop end value.the end value is the length of the json array.
I am using ${array.length ()} this.but getting number format exception.
-
It would help if we could look at an example JSON object that needs to be parsed, so we can provide a more detailed answer. Could you please edit your question to include this?Shotgun Ninja– Shotgun Ninja2015-05-18 14:21:34 +00:00Commented May 18, 2015 at 14:21
-
@ShotgunNinja [{"state":"WEST BENGAL","so/bo":"Ajodhya B.O","district":"Bankura","taluk":"Vishnupur"},{"state":"WEST BENGAL","so/bo":"Amral B.O","district":"Bankura","taluk":"Bishnupur"}] This is my json array I'm passing to the jsp using ModelAndView.addObject("name",JSONObject) maibnly I am Facing problem in Iterating the JsonArray using for each loop of jstl core. If You have any solution please help me.Sayak Choudhury– Sayak Choudhury2015-05-19 04:35:13 +00:00Commented May 19, 2015 at 4:35
Add a comment
|
1 Answer
I Got the Solution:
'<table>
<tr>
<% int lengthOfArray =(Integer)request.getAttribute("length");
%>
</tr>
<c:forEach var="i" begin="0" end="<%=lengthOfArray-1 %>">
<tr>
<td>
<c:out value="${array.getJSONObject(i).getString('soBoOrZipcode')}"/>
</td>
<td>
<c:out value="${array.getJSONObject(i).getString('taluk')}"/>
</td>
<td>
<c:out value="${array.getJSONObject(i).getString('district')}"/>
</td>
<td>
<c:out value="${array.getJSONObject(i).getString('state')}"/>
</td>
</tr>
</c:forEach>
</table>'