Skip to content Skip to sidebar Skip to footer

Com.google.gson.jsonsyntaxexception: Expected Begin_array But Was String

I am facing this error in parsing json data : Expected BEGIN_ARRAY but was STRING at line 1 column 1156 I could'nt find the solution. My json data is : { 'project': [

Solution 1:

The Exception is thrown when you try to parse the field "icon", because in your JSON response there is a string, and you try to parse it as a byte[].

Since in your class, icon is an array of bytes, when it tries to parse the field "icon" it says it "expected an array", but in the JSON response "icon" is not an array (there's nothing surrounded by [ ]), so it says "but was a string"...


EDIT: That said, in order to fix it, the easiest way in my opinion is to change the type of icon for a String to parse it correctly, and then do the conversion to byte[] somewhere else... For example you can have a method in the class, let's say public byte[] getIconAsByteArray() {...}, that does the conversion.

Otherwise, and this is probably the most elegant solution, you need to write a custom deserializer.

Post a Comment for "Com.google.gson.jsonsyntaxexception: Expected Begin_array But Was String"