从Java Servlet接收的ArrayList作为JSON循环

时间:2016-11-03 17:41:32

标签: java arrays json jsp servlets

这是我的jsp文件代码。

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
      <script>
        debugger;
        </script>
            <h1>Products</h1>
            <table>
                <tr>
                    <th>ID</th>
                </tr>
                <c:set var="count" value="0" scope="page" />


                <c:forEach items="${myList}" var="myList">
                    <tr>


                        <td>${myList}</td>
                    </tr>

                </c:forEach>
           </table>

        </body>


    </html>

打印myList后得到的响应是

  

[{&#34; type&#34;:&#34; Point&#34;,&#34; coordinates&#34;:[71.2321239,30.9569219]},{&#34; type&#34;:   &#34; Point&#34;,&#34; coordinates&#34;:[74.04084713,31.27679252]},{&#34; type&#34;:&#34; Point&#34;,   &#34;坐标&#34;:[73.1061811,33.6336417]}]

它总共包含3个元素。当我打印myList.size()时它也会显示我3.现在我想使用索引号打印所有这些数组元素,例如myList[index]带有for循环。如何实现另一个for循环使用索引号打印数组元素。

0 个答案:

没有答案