【发布时间】:2019-09-25 07:10:37
【问题描述】:
我在 php 中使用 volley 并返回错误,其结构如下,如 postman 所示
{
"name": "Exception",
"message": "Unable to verify your accont",
"code": 500,
"type": "yii\\base\\UserException"
}
现在我想阅读上面的错误消息,所以在我的排球字符串请求中我有
StringRequest stringRequest = new StringRequest(this.request_method, this.api_url,
response -> {
},
error -> {
//here process the error
if (error instanceof ServerError || error instanceof AuthFailureError){
NetworkResponse response = er.networkResponse;
switch (response.statusCode){
case 500:{
HashMap<String, String> result = new Gson().fromJson(....); //stuck
}
}
}) {
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
};
我坚持如何从凌空错误中读取错误消息。我如何在有或没有 gson 的情况下进行
我仍然想使用字符串请求,因为我希望我的 php 响应是一个 json 编码的字符串。
【问题讨论】: