解决请求成功和失败时服务器返回的data数据的结构不一样的问题(Gson自定义解析) #234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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": “” } }