Strange error occurred when parsing into list using GSON in android

W/System.err: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 2 path $
at com.google.gson.Gson.fromJson(Gson.java:944)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
at com.example.administrator.woleme.shop_list.parseJSON(shop_list.java:93)
at com.example.administrator.woleme.shop_list.access$000(shop_list.java:30)
at com.example.administrator.woleme.shop_list$1 1. O n R e s p O n s e ( s h O p l i s t . j a v a : 70 ) a t o k h t t p 3. i n t e r n a l . c o n n e c t i o n . R e a l C a l l 1.onResponse(shop_list.java:70) at okhttp3.internal.connection.RealCall AsyncCall.run(RealCall.kt:504)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
W/System.err: Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 2 path $
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory A d a p t e r . r e a d ( C o l l e c t i o n T y p e A d a p t e r F a c t o r y . j a v a : 80 ) a t c o m . g o o g l e . g s o n . i n t e r n a l . b i n d . C o l l e c t i o n T y p e A d a p t e r F a c t o r y Adapter.read(CollectionTypeAdapterFactory.java:80) at com.google.gson.internal.bind.CollectionTypeAdapterFactory Adapter.read (CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson (Gson.java:932)

Solution: Checked a lot of information on the external network, some people said that it can be solved by cleaning the project, but my program still does not run normally, and then I saw a solution to Expected BEGIN_OBJECT but was STRING on Stack Overflow. I received it. Inspiration

I added two lines of code to my program
Insert picture description here
and then solved it. I hope to inspire you

Published 3 original articles · Likes0 · Visits17

Guess you like

Origin blog.csdn.net/weixin_42653023/article/details/105667194