how to solve “Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $ ” [closed]

ぃ、小莉子 提交于 2019-12-25 01:48:41

问题


I'm facing problem when I run the app on my mobile and when I run the error with stack trace or with debug option there is no error so I don't know what to do Here's the error message

Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'.

java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path` $


回答1:


This usually happens when your model is expecting a JSON array value but was surprised by a String value so it threw an exception. You can solve this in two different ways:

1- Edit your API response to return an empty JSON array or a JSON array with only one value in it. I mean always wrap your response value in a JSON array.

2- Edit your model to accept all data types, you can use Object as the data type for this value then cast it to an array or to a single value only.

Hope this helps, happy coding!



来源:https://stackoverflow.com/questions/47884928/how-to-solve-expected-begin-array-but-was-string-at-line-1-column-1-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!