【发布时间】:2018-02-13 11:30:02
【问题描述】:
所以我在 Android Studio 中为一个具有登录功能的网页构建了一个 Android 应用。我已经成功地将应用程序连接到网站数据库,我可以登录并从服务器获得响应。应用程序正在响应中查找错误值,但响应中不包含错误值。
这是我的应用程序中的代码:
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);
// Launch main activity
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
这是登录成功时服务器给出的响应:
Login Response: {"howislife":1,"rekeningnummer":"212220","soortuser":"student","datum":"05 Sep 2017"}
所以当登录成功时会显示“howislife:1”,当密码或用户名不正确时会显示“howislife:2”或“howislife:3”。因此,我的 Android 应用程序中的代码需要检查“howislife”的值是什么。我怎样才能做到这一点?提前致谢!
【问题讨论】:
-
试试这个教程:androidhive.info/2012/01/android-json-parsing-tutorial希望对你有帮助
标签: java android json server response