当密码和确认密码输入正确时,我的响应成功显示......但是当它不匹配时,它不会显示其他部分......不显示任何内容......请指导我......需要帮助。 ..提前致谢
这是当邮递员中密码和确认密码输入错误时我的回复:-
{
"status": 500,
"message": "Could not reset password.",
"error": {
"confirm_password": {
"compareWith": "Passwords mismatch."
}
},
"user_msg": "Could not reset password, please try again."
}
这是我的数据类:-
1-->
data class Reset_Reponse_Base (
@SerializedName("status") val status : Int,
@SerializedName("message") val message : String,
@SerializedName("error") val error : Reset_Response_error,
@SerializedName("user_msg") val user_msg : String
)
2-->
data class Reset_Response_error (
@SerializedName("confirm_password") val confirm_password : Reset_Response_Confirm_password
)
3-->
data class Reset_Response_Confirm_password (
@SerializedName("compareWith") val compareWith : String
)
我的响应通话活动:--->
var old_password = findViewById<TextView>(R.id.old_password)
var new_password = findViewById<TextView>(R.id.new_password)
var confirm_password =
findViewById<TextView>(R.id.confirm_new_password)
val resetpwdbutton = findViewById<Button>(R.id.resetpwdbtn)
resetpwdbutton.setOnClickListener {
val old = old_password.text.toString().trim()
val new = new_password.text.toString().trim()
val confirm = confirm_password.text.toString().trim()
val token: String =
SharedPrefManager.getInstance(
applicationContext
).user.access_token.toString()
RetrofitClient.instance.resetpassword(token, old, new, confirm)
.enqueue(object : Callback<Reset_Reponse_Base> {
override fun onFailure(call: Call<Reset_Reponse_Base>, t: Throwable) {
Log.d("res", "" + t)
}
override fun onResponse(
call: Call<Reset_Reponse_Base>,
response: Response<Reset_Reponse_Base>
) {
var res = response
if (res.body()?.status == 200) {
Log.d("response check ", "" + response.body()?.status.toString())
if (res.body()?.status == 200) {
Toast.makeText(
applicationContext,
res.body()?.user_msg,
Toast.LENGTH_LONG
).show()
Log.d("kjsfgxhufb", response.body()?.user_msg.toString())
} else if (res.body()?.status == 500){
val ret: Reset_Response_error = res.body()!!.error
val ret2: Reset_Response_Confirm_password = ret.confirm_password
//confused over here-->
//toast is not getting diaplayed when password and confirm password doesnt match
try {
val jObjError =
JSONObject(response.errorBody()!!.string())
Toast.makeText(
applicationContext,
jObjError.getString("message")+jObjError.getString("user_msg"),
Toast.LENGTH_LONG
).show()
} catch (e: Exception) {
Toast.makeText(applicationContext, e.message, Toast.LENGTH_LONG).show()
Log.e("errorrr",e.message)
}
}
}
}
})
}
更换这个后else if (res.body()?.status == 500)
by else if (!res.isSuccessful
==> 调试器中为 false
但如果我这样做-->else if (res.errorBody()?.equals(500)!!)
我得到这个-->
这很好,但是我怎样才能在这个下访问[size=176 text={"status":500,"message":"Could not reset password.","error":{"co…]
我在内容下的错误下有错误消息
我想检索 ==> 消息":"无法重置密码。"错误":{"co......