Getting json from retrofit's response errorBody

后端 未结 2 1537
眼角桃花
眼角桃花 2021-02-07 17:24

I am struggling with retrofit. When I post a request in my browser i get such a request:

And that\'s what I expect. However, when I try to parse this in my app I kept g

2条回答
  •  后悔当初
    2021-02-07 18:04

    you use string(), not toString()

     ErrorResponse errorResponse = gson.fromJson(
                    response.errorBody().toString(),
                    ErrorResponse.class);
    

    to

    ErrorResponse errorResponse = gson.fromJson(
                    response.errorBody().string(),
                    ErrorResponse.class);
    

提交回复
热议问题