我想播放框架将arraylist发送到我的Android应用程序。所以我可以在Android应用程序上查看列表。 但是play框架无法返回ArrayList) 我怎么解决这个问题? 谢谢。
public static Result get_LatestList() throws ClassNotFoundException,
SQLException {
String latestList = "";
ArrayList<String[]> etList = new ArrayList<String[]>();
MultipartFormData body = request().body().asMultipartFormData();
String pageNumber = body.asFormUrlEncoded().get("pageNumber")[0];
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/iea_db",
"rt", "yt");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from List_Table;");
while (rs.next()) {
String[] oneSet = new String[4];
oneSet[0] = rs.getString("userName");
oneSet[1] = rs.getString("idName");
oneSet[2] = rs.getString("comment");
oneSet[3] = rs.getString("rank");
etList.add(oneSet);
}
conn.close();
return ok(etList);
}
答案 0 :(得分:0)
我找到了一个解决方案:使用Json 在游戏框架中,执行以下操作:
ObjectNode result = Json.newObject();
result.put("draw", Integer.valueOf(params.get("draw")[0]));
result.put("recordsTotal", iTotalRecords);
result.put("recordsFilter", iTotalDisplayRecords);
return ok(result);
在android中,执行此操作:
@Override
protected JSONObject doInBackground(String... _uri) {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(_uri[0]);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
httpResponse.getEntity().writeTo(outputStream);
outputStream.close();
return new JSONObject(outputStream.toString());
} else {
httpResponse.getEntity().getContent().close();
throw new IOException();
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}