【发布时间】:2017-01-06 05:37:53
【问题描述】:
嗨,我正在使用 volley 解析我的 api,当我传递有效凭据时,它可以正常工作给我 ab auth 令牌,如果凭据错误,我仍然希望它解析响应,但它给了我“没有身份验证发现的挑战”和JSONObject 响应为null 响应作为回报。是 volley 的问题还是 php 脚本的问题??
private void sendRequest_getAuth(){
try {
JSONObject jsonBody = new JSONObject();
jsonBody.put("phone", "phn in numeric");
jsonBody.put("password", "pswd");
JsonObjectRequest JSONRequest = new JsonObjectRequest(Request.Method.POST, "the api url", jsonBody,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
jresponse=response;
show_getAuth(jresponse);
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("onError_response",jresponse.toString());
Toast.makeText(LoginActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
show_getAuth(jresponse);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(JSONRequest);
}
需要解析的响应:-
{
"errors": [
{
"message": "Invalid Credentials"
}
]
}
【问题讨论】:
-
你应该在服务器端做,...
标签: android json parsing android-studio parse-platform