arraysjsonjstljsonobjectrequestjstl-functions

How to iterate through JSON Array or JSON object in JSP using JSTL


I'm having this json:

{
"maxAgentAmt": 66,
"minComAmt": 3,
"maxTxn": 7,
"maxAmt": 99,
"minAmt": 3,
"maxComAmt": 99
}

and I also have to get values from json array having multiple json objects:

 [{
    "comType": "V",
    "comValue": 5757,
    "comMode": "E",
    "maxAmt": 7575,
    "minAmt": 3,
    "comGSTMode": "E"
}, {
    "comType": "E",
    "comValue": "E",
    "comMode": "V",
    "maxAmt": 8,
    "minAmt": 4,
    "comGSTMode": 8
}]

This is for Json Object:

<c:if test="${not empty list}">
      <c:forEach items="${list.getJSONObject(\"maxAgentAmt\")}" 
              var="list" varStatus="rowCounterCh">
              <li>${maxAgentAmt}</li>
      </c:forEach>
 </c:if>

And, I don't know how to iterrate jsonarray having multiple json objects


Solution

  • Finally I got some solution :

    <%

    String shareRule = (String) session.getAttribute("shareRule");

    JSONObject shareRuleJson = new JSONObject(shareRule);

    String tdsFlag = shareRuleJson.get("tdsFlag").toString();

    %>

    value="<%=tdsFlag%>"

    Same, if user want to iterate json array then he will do the same for json array case also.

    This will solve my problem. I hope it will solve somebody also