Gson Expected Begin_array But Was String At Line 1 Error
I am trying to parse a String array using Retrofit and GSON which is returned from the API: This is what the response normally looks like (CASE 1): ['Scan finished, scan informatio
Solution 1:
"Expected BEGIN_ARRAY but was STRING" means that the character Gson is parsing is a "
, but it expected a [
(since you're trying to parse a list). Since the input doesn't correspond to the expected input, Gson has to fail. From Gson's perspective the case 2 input isn't any different than the case 1 input (and if nulls were an issue, the error message would say something to that effect).
Since this input isn't trusted (it's coming from a third-party server?) you should add some error handling code around the parse call, in order to account for the possibility that the input is malformed. At a minimum logging the received input upon failure would immediately make it clear that you're not receiving the expected array.
Post a Comment for "Gson Expected Begin_array But Was String At Line 1 Error"