调用 gson.fromJson(json, tClass)方法时,抛出异常_ com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 28 path $.errors

调用 gson.fromJson(json, tClass)方法时,抛出异常_ com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 28 path $.errors……

原因:传入的json串中有的value为空,具体在json串中表现为[],例如以下串中 key 为 errors 时的value 为 []。

"{'errorNumber':0,'errors':[],'accessToken':'0c43905a-c9a4-4e38-a3e1-60cd35ee8008','tokenType':'bearer','scope':'read','expiresIn':19176,'applicationAPIDto':{'name':'JWT','applicationId':'greatlifejwt4','applicationUuid':'04db6ffeea1460039390aeefd438eccbfBmipgccs6C','logoUuid':'','startUrl':null,'createTime':'2018-09-06 18:13','description':'JWT Application(OIDC)','enabled':true,'supportDeviceTypes':['WEB','MOBILE','PC'],'existAccountLinking':false,'enableTwoFactor':false,'applicationUsernames':[]}}

解决思路:首先提换掉[],然后再调用gson.fromJson(json, tClass)方法。

具体实现:

酱紫就没有问题啦!

猜你喜欢

转载自www.cnblogs.com/Aqhour/p/9645558.html