0

我正在用 android 解析 GSON,我想解析我的 MySQL 表中的数据。我的 GSON 对象是:

{"data":
   [
   {"country":"Ireland", "capital": "Dublin"},
     {"country":"Hungary", "capital": "Budapest"},
     {"country":"Democratic Republic of the Congo", "capital": "Kinshasa"}
     ]
   }

这个对象对我有用,我可以在我的手机中看到它。不过,如果我从 mysql 数据库添加我的结果集代码,如下所示:

<%

    try { Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "root", "root");
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("select * from capitals");
    while (rs.next()) {                      
        %>             
        {"data":
           [
           {"country":"Ireland", "capital": "<% rs.getString(1); %> "},
             {"country":"Hungary", "capital": "<% rs.getString(2); %>"},
             {"country":"Democratic Republic of the Congo", "capital": "Kinshasa"}
               ]
           }
                            <%
                         }
                        } catch (Exception e) {
                        }
                    %>

应用程序失败,并告诉我“不幸的是,应用程序停止了”。这是我的日志: http: //pastebin.com/8bz5QbjR 它写道,第 29 行是 EOF。哪条线?在我的 Activity(android) 中还是在我的 GSON 对象中?

4

0 回答 0