我正在使用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对象中?