【发布时间】:2015-05-22 12:02:01
【问题描述】:
我有一个托管在“heroku”上的应用程序。它有这个方法,您可以通过 get 调用它,它会以“Json 代码”响应
public static Result renderManga(int id) {
Manga m = Manga.find.byId(id);
if (m != null) {
return ok(Json.toJson(m));
} else
return null;
}
}
路由文件
GET /srvc/manga/:id controllers.Services.renderManga(id:Integer)
现在是我的安卓代码
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet("https://boku-no-manga.herokuapp.com/srvc/manga/5"));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
String responseString = out.toString();
EditText res = (EditText) findViewById(R.id.result);
res.setText(responseString);
Log.i("JSONmymanga",responseString);
out.close();
} else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (Exception e) {}
我想接收我的 play 应用发送的 JSON 代码并在我的 android 应用中使用它。
【问题讨论】:
-
那么你还在纠结 JSON 解析吗?
-
我还没到那里,我什么都没收到......
标签: java android json playframework-2.2