【发布时间】:2019-03-13 11:00:49
【问题描述】:
虽然问题已得到解答,但解决方案对我不起作用。我在这里使用Volley 库。我也收到了来自服务器的响应,但这仍然是导致问题的原因。你们能告诉我我做错了什么吗?
我的代码:
StringRequest stringRequest = new StringRequest(Request.Method.POST, forgetPassword_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("response", response);
try {
JSONArray jsonArray = new JSONArray(response);
JSONObject jsonObject = jsonArray.getJSONObject(0);
String code = jsonObject.getString("code");
if (code.equals("mail_send")) {
AlertDialog.Builder builder = new AlertDialog.Builder(Signin.this);
builder.setCancelable(false);
builder.setMessage("Password will be sent to your registered email id.");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//if user pressed "yes", then he is allowed to exit from application
dialog.cancel();
EmailText.setVisibility(View.VISIBLE);
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(Signin.this);
builder.setCancelable(false);
builder.setMessage("Email id is not registered.");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//if user pressed "yes", then he is allowed to exit from application
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
-
检查您的回复,我认为它不是 json 数组
-
这是我得到的响应:[{"code":"mail_send","message":"mail send to the register email id","Password":"12345"}]跨度>
-
发布完成异常
-
03-13 16:25:19.222 10109-10109/com.Dignc.texrecruit D/响应:无法执行:/usr/sbin/sendmail [{"code":"mail_send"," message":"mail send to the register email id","Password":"12345"}] 03-13 16:25:19.222 10109-10109/com.Dignc.texrecruit W/System.err: org.json.JSONException : java.lang.String 类型的值不能转换为 JSONArray
标签: android json android-volley jsonexception