无法通过json成功...光标不会尝试块

时间:2014-05-08 10:50:08

标签: android android-json

我让用户通过网络服务检索忘记密码。所有函数都在执行json给出成功输出但是在调试器没有进入try(if else)条件...

我的遗忘响应:

{
status: "Success" 
msg: "Password has been sent your Email_id , Please check it.."
}

尝试/捕获

params.add(new BasicNameValuePair("email",Email));

JSONObject json = jsonParser.makeHttpRequest(url,"POST", params);
Log.d("Create Response", json.toString());
try{
    String status=json.getString(TAG_SUCCESS);
    if(status=="TAG_SUCCESS"){

        Toast.makeText(ForgetPassWord.this,"Password has been sent your Email_id , Please check it..", Toast.LENGTH_LONG).show();
        finish();
    }else{
        Toast.makeText(ForgetPassWord.this,"Please Enter Correct E-Mail", Toast.LENGTH_LONG).show();
    }
}catch(JSONException e) {
    e.printStackTrace();
}
return null;

2 个答案:

答案 0 :(得分:1)

使用equals()进行字符串比较

status.equals("Success")

编辑:

如下所示进行更改

  private static final String TAG_SUCCESS="status";// Because  status is the key

String status = json.getString(TAG_SUCCESS);

答案 1 :(得分:1)

试试这个

try {

            if (json.has((TAG_SUCCESS))) {
                String status = json.getString(TAG_SUCCESS);
                if (status.equals(TAG_SUCCESS)) {

                    Toast.makeText(
                            ForgetPassWord.this,
                            "Password has been sent your Email_id , Please check it..",
                            Toast.LENGTH_LONG).show();
                    finish();
                }

                else {
                    Toast.makeText(ForgetPassWord.this,
                            "Please Enter Correct E-Mail",
                            Toast.LENGTH_LONG).show();
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }