com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
at com.google.gson.Gson.fromJson(Gson.java:826)
at com.google.gson.Gson.fromJson(Gson.java:779)
at com.google.gson.Gson.fromJson(Gson.java:728)
at readtv.ghs.tv.util.RewardRuleUtil$1.onSuccess(RewardRuleUtil.java:63)
at readtv.ghs.tv.http.AsyncHttpClient$2$2.run(AsyncHttpClient.java:116)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5013)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)
Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.Gson.fromJson(Gson.java:814)
... 12 more
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.Gson.fromJson(Gson.java:814)
at com.google.gson.Gson.fromJson(Gson.java:779)
at com.google.gson.Gson.fromJson(Gson.java:728)
at readtv.ghs.tv.util.RewardRuleUtil$1.onSuccess(RewardRuleUtil.java:63)
at readtv.ghs.tv.http.AsyncHttpClient$2$2.run(AsyncHttpClient.java:116)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5013)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)
Often this kind of problem, I hope you can tell me how to deal with the simple. Or where it is. I don't think it's our problem.
The exception indicates the problem. The type you asked Gson to deserialize
was a list or array but the JSON contained a string or wasn't JSON at all
(and thus appeared like a string).
On Sun, Nov 27, 2016, 3:04 AM LucianWang notifications@github.com wrote:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
at com.google.gson.Gson.fromJson(Gson.java:826)
at com.google.gson.Gson.fromJson(Gson.java:779)
at com.google.gson.Gson.fromJson(Gson.java:728)
at readtv.ghs.tv.util.RewardRuleUtil$1.onSuccess(RewardRuleUtil.java:63)
at readtv.ghs.tv.http.AsyncHttpClient$2$2.run(AsyncHttpClient.java:116)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5013)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)
Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was
STRING at line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350)
at
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
at
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.Gson.fromJson(Gson.java:814)
... 12 more
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at
line 1 column 1 path $
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350)
at
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)
at
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.Gson.fromJson(Gson.java:814)
at com.google.gson.Gson.fromJson(Gson.java:779)
at com.google.gson.Gson.fromJson(Gson.java:728)
at readtv.ghs.tv.util.RewardRuleUtil$1.onSuccess(RewardRuleUtil.java:63)
at readtv.ghs.tv.http.AsyncHttpClient$2$2.run(AsyncHttpClient.java:116)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5013)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)Often this kind of problem, I hope you can tell me how to deal with the
simple. Or where it is. I don't think it's our problem.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/966, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEZ7Q9ENsJiHfxUpQMEVlZRWlsbk6ks5rCTmhgaJpZM4K9FyN
.
Thank you.
Hi I have the same problem and this happened all of a sudden previously it was working fine,i'm having a real hard time analyzing what has changed that led to this problem,can someone please have a look at this and help me out,
if the formatting here is not clear, i have posted in stackoverflow
https://stackoverflow.com/questions/48840747/onfailure-methods-throws-exception-expected-begin-array-but-was-string-at-line
I have this Json Response coming from server:
[{
"disposal_type_category": {
"category_entry_total": "21"
},
"disposal_types": [{
"ID": "78",
"entries": [{
"ID": 2584,
"entry_tally": "1"
},
{
"ID": 2578,
"entry_tally": "1"
}
]
},
{
"ID": "1323",
"entries": [{
"ID": 2583,
"entry_tally": "1"
},
{
"ID": 2579,
"entry_tally": "1"
}
]
}
]
},
{
"disposal_type_category": {
"category_entry_total": "25.2"
},
"disposal_types": [{
"ID": "80",
"entries": []
},
{
"ID": "84",
"entries": []
}
]
}
]
This is in my ApiClient.java:
public static Retrofit getClient() {
if (retrofit==null) {
Gson gson = new GsonBuilder().setLenient().create();
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
This is in ApiInterface.java:
Call<List<Disposal>> getCollection(@Header("Authorization") String token);
Disposal.java:
public class Disposal {
@SerializedName("disposal_type_category")
@Expose
public DisposalTypeCategory disposalTypeCategory;
@SerializedName("disposal_types")
@Expose
public List<DisposalType> disposalTypes = null;
}
DisposalTypeCategory.java:
public class DisposalTypeCategory {
@SerializedName("category_entry_total")
@Expose
public String categoryEntryTotal;
}
DisposalType.java:
public class DisposalType {
@SerializedName("ID")
@Expose
public String iD;
@SerializedName("entries")
@Expose
public List<Entries> entries = null;
}
Entries.java:
public class Entries {
@SerializedName("ID")
@Expose
private int iD;
}
I have set setLineant(true) for Gson because if i remove it i will get malformed json exception, even this issue started recently previously was fine, not sure if its related.
The issue started after 2-3 new fields were added to API and the base url was changed but still the core remains same.
how do you solve this problem
@kalyakiplangat for me checking everything again with the backend developer and seeing if any API response is returning something not as expected by the app. There were changes made in return format of the API response by backend Dev which I wasn't aware of..so I was expecting string in app but API was sending array
I have not declared JSON or Gson anywhere , but why I'm getting error
@uniquelipu try to clean the project, you can go build >> clean project, for me, it worked
Cleaning the project worked for me
Cleaning the project worked for me as well
Clean the Project
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
I got a similar error message but cleaning the app did the trick for me
it worked for me too..
cleaning and rebuilding the project helped me to solve this problem...
for me too.
for me too
For me the problem was this one -> java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 12 column 11 path $.items[0].id
Changing @SerializedName("id") val id: Id
to @SerializedName("id") val id: String
worked.
If someone is getting this error in AndroidStudio :
Try two things:
I'm fairly new to android. Excuse any mistakes if committed.
Suggestions are welcome :)
Please go to Build, then clean. This option worked for me.
Please go to Build, then clean. This option worked for me.
Happy learning :)
After cleaning project and rebuilding, still I'm having issue with the same error. Don' t know how to resolve as i already checked all parameter naming conventions not once but thrice.
Thanks bro, cleaning project worked for me
@uniquelipu try to clean the project, you can go
build >> clean project, for me, it worked
whoa it worked thanks for sharing.
Rebuilding the project will fix the issue.
cleaning and rebuilding did the trick
thanks alot cleaning the project is remedy for the error
i got this:
Expected BEGIN_OBJECT but was STRING at line 1 column 2
i solve by:
you need an object "Class", but you got List<"Class">
so your API need to return response using $data: Class::find()->first();
dont use get() or all();
I got this problem when making some changes to square calendar widget.
But thankfully, I solved it by cleaning and rebuilding the project!
I hate these errors that come out of blue without reason ;/
cleaning project and rebuilding worked for me as well
Cleaning the project worked for me
gradlew clean worked for me.
plz suggest the solution of the error
Here are two answer on stack overflow for the same type of issue. Plz, have a look once.
https://stackoverflow.com/questions/28418662/expected-begin-object-but-was-string-at-line-1-column-1
clean project and rebuild project doesn't work for my issue
https://stackoverflow.com/questions/60568620/retrofit2-get-method-failure-response
It's weird but I am still getting this error even did everything listed on the web. What my case is I am trying to update the app over the existing one. They both separately working well without error but when I try to update latest version over the previous one I am receiving the following exception;
java.lang.IllegalStateException: Expected an int but was BEGIN_ARRAY at line 1 column 99 path $[0].e
There is no error in the retrieved Json file. The funny thing is when I revert my code all working well. And in that code I am using sorting like comparable and comparator over serialized class.
Cleaning and rebuiding the project didnt work for me! iam getting the same exception again and again
Cleaning the app did it for me
Thanks
On Wed, 24 Jun 2020, 8:21 pm Adebisi Adetoba, notifications@github.com
wrote:
Cleaning the app did it for me
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/966#issuecomment-648869280, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AGK3TMPFS464OKZPIQBNTILRYIHF7ANCNFSM4CXULSGQ
.
@uniquelipu try to clean the project, you can go
build >> clean project, for me, it worked
i am not getting option of clean project in build dropdown? How to enable it
First :- clean and rebuild
if it not worked then
Second:- Just delete previous release apk folder
i am not getting option of clean project in build dropdown? How to enable it
First :- clean and rebuild
if it not worked then
Second:- Just delete previous release apk folder
i am not getting option of clean project in build dropdown? How to enable it
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
I got a similar error message but cleaning the app did the trick for me
how to clean the app?
Most helpful comment
@uniquelipu try to clean the project, you can go
build >> clean project, for me, it worked