Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2相关的知识,希望对你有一定的参考价值。

原因是解析的时候多了,逗号,或是 \

解决方法:
revJson=revJson.replace("\\", "");//去掉‘/‘
revJson=revJson.substring(1, revJson.length()-1); //去掉头尾引号。
 
简单对象解析:
 BeanOrderIntent beanOrder = (BeanOrderIntent) DubJson.fromJson(result, BeanOrderIntent.class);
 
List解析
Gson gson = new Gson();
List<BeanOrderConfirm> beanOrderConfirm = gson.fromJson(deliveryData, new TypeToken<List<BeanOrderConfirm>>() {}.getType());

 

以上是关于Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2的主要内容,如果未能解决你的问题,请参考以下文章

为啥 Gson fromJson 会抛出 JsonSyntaxException: Expected BEGIN_OBJECT but was BEGIN_ARRAY?

Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $