Closed RookieExaminer closed 2 months ago
这是什么神仙操作,只能手动分两步解析了,如下:
override fun onParse(response: okhttp3.Response): T {
val responseStr: Response<String> = response.convertTo(Response::class, String::class.java)
if (responseStr.code == 0) {
return GsonUtil.fromJson<T>(responseStr.data, types[0])
} else {
throw ParseException(responseStr.code.toString(), responseStr.data, response)
}
}
responseStr.cod=1 可解析 data string类型
responseStr.code=0报错 解析data为 DataBean 对象时报错
2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at rxhttp.wrapper.utils.GsonUtil.fromJson(GsonUtil.java:59) 2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at com.azheng.coinkeep.net.converter.ResponseParserBitApi.onParse(ResponseParserBitApi.kt:65) 2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at rxhttp.wrapper.utils.Utils$await$2$2.onResponse(Utils.kt:37) 2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519) 2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 2024-08-06 11:03:52.279 31523-31523 RxHttp com.coinkeep.wallet.new E at java.lang.Thread.run(Thread.java:919) 2024-08-06 11:03:52.280 31523-31523 Toaster com.coinkeep.wallet.new I (QuickExchangeFragment.kt:425) The string 'null' could not be deserialized to class com.azheng.coinkeep.bean.DataBean object
rxhttp.wrapper.utils.GsonUtil
@NotNull
public static
不好意思,还是没有解决
已经提示的很清楚了,fronJson传入了null
实际上data是有数据的,只不过解析错误了。 com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 21 path $.data
请copy我贴出的代码
用的就是这个代码
code=0 data不是string类型 {"code":0,"data":{}} code 1 data是string类型 {"code":1,"data":"暂无对应资金池,请切换币种"}
感谢,解决了 原因是设置了全局转换器问题 设置为非框架转换器了 setConverter(GsonConverter.create(GsonUtils.getGson()))
你好,请教一下。 rxhttp_version = '3.3.0-beta2' okhttp:4.12.0 服务器正确返回 {"code":0,"data":{}} 服务器错误返回 {"code":1,"data":"暂无对应资金池,请切换币种"}
报错:rxhttp.wrapper.exception.ParseException: code is 1, null
服务器正确时是可以拿到data的,解析成DataBean。 怎么能在服务器返回data类型为string时,也可以拿到data数据