Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决请求成功和失败时服务器返回的data数据的结构不一样的问题(Gson自定义解析) #234

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

zhumj
Copy link

@zhumj zhumj commented Sep 22, 2020

1,增加国际化,目前可用的英语,汉语和日语。
2,修改ApiResultFunc类,一定程度解决了请求成功和失败的时候,数据返回不同类型导致Gson解决错误的问题,例如:
请求成功时
{code :0,message:“请求成功”,data:{... json数据...} }
请求失败时
{code:0,message:“请求失败”,data:“空” }
此解决方案是通过自定义Gson的TypeAdapter来解析数据,当前只能适配到data一级,当以下数据结构时依然会报解析错误(当然这已经足够解决请求成功和失败的时候,数据data返回不同类型导致Gson解决错误的问题,还不影响自定义ApiResult):
期待结构:
{code :0,message:“请求成功”,data:{ "info": {} } }
服务器返回结构:
{code :0,message:“请求成功”,data:{ "info": “” } }

zhuminjun and others added 7 commits September 17, 2020 15:06
…ese, and Japanese.

2、Modifying the ApiResultFunc class, to a certain extent, solves the problem of Gson parsing errors caused by data returning different types when the request succeeds and fails, for example:
When the request is successful:
{ code: 0, msg: "successful", data: {...json string...} }
When the request fails:
{ code: 0, msg: "fails", data: “null” }
…30.0.2”;

2、依赖的第三方库使用 api 添加,因为使用 implementation 会报“Cannot access class 'io.reactivex.disposables.Disposable'. Check your module classpath for missing or conflicting dependencies.”错误;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant