我让用户通过网络服务检索忘记密码。所有函数都在执行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;
答案 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();
}