json rest api在android中使用,并根据响应进行登录

omtl5h9j  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(477)

我正在主活动中使用jsonapi。
如果api响应为 1 .
在下面的代码中,如果 server_result.eqaulignorancecase(1) 然后登录,但它将直接进入else状态。

public void perforLOginTask(final String usernme, final String pass) {
    dialog.setMessage("Please wait.");
    dialog.show();
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            JSONObject jsonParams = new JSONObject();
            try {
                jsonParams.put("loginId", usernme);
                jsonParams.put("passwrd", pass);
                jsonParams.put("mt_key", "1");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            System.out.println("jsonParams " + jsonParams.toString());
            final String server_result = WebUtils.getPostResponse(MainActivity.this, jsonParams, "http://api.loginoffice.com/getresponse_eyp.aspx" , "", "");
            System.out.println("server_result" + server_result);
            Log.d("check","server result"+server_result);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    dialog.dismiss();
                    if (server_result.equalsIgnoreCase("SUCCESS")) {
                        SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
                        editor.putString("logout", "1");
                        editor.putString("user_id", Singleton.getInstance().userid);
                        editor.apply();
                        editor.commit();
                        txt_loginid.setText("");
                        txt_password.setText("");
                        Intent intent = new Intent(MainActivity.this, home.class);
                        startActivity(intent);
                        finish();
                    } else {
                      Toast.makeText(MainActivity.this, "Please enter correct login id and password", Toast.LENGTH_LONG).show();
                    }
                }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题