Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从AJAX检索ArrayList Json对象_Java_Jquery_Json_Ajax - Fatal编程技术网

Java 从AJAX检索ArrayList Json对象

Java 从AJAX检索ArrayList Json对象,java,jquery,json,ajax,Java,Jquery,Json,Ajax,我有以下从数据库检索数据的代码: List<LocationBean> Locations = new ArrayList<LocationBean>(); /* * The following logic iterates through the database entries * */ for(int i = 1; i<=10; ++i){ String quer

我有以下从数据库检索数据的代码:

List<LocationBean> Locations = new ArrayList<LocationBean>();

        /*
         * The following logic iterates through the database entries
         * */

        for(int i = 1; i<=10; ++i){

            String query ="SELECT * FROM Energyinfo.Info WHERE id_number = " +i;
            ResultSet rs = stmt.executeQuery(query);


            while(rs.next()){
                int id = rs.getInt("id_number");
                int kw = rs.getInt("kilowatts_used");
                double lat = rs.getDouble("Latitude");
                double lon = rs.getDouble("Longitude");
                LocationBean temp = new LocationBean(id, kw, lat, lon);
                Locations.add(temp);


        }}
        String jsonData = new Gson().toJson(Locations);
        System.out.println(jsonData);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(jsonData);
List Locations=new ArrayList();
/*
*以下逻辑遍历数据库条目
* */

对于(int i=1;iI应该提到这段代码在Servlet中的一个doGet方法中如果你只想发送
json
为什么不创建一个
json
?你能给出一个例子吗?PS我如何检索前端的每个json对象?回答你的最后一个问题:用JavaScript函数解析它们。