Gson error when parsing empty arrays [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this questionI'm parsing JSON using GSON, but get an error when I try to parse JSON containing an empty array.
This is the JSON:
{"Selected":[{"RelatedProducts":[],"ProductReview":null,"ProductId":94}]}
and the error produced:
com.google.gson.JsonParseException: Expecting object found: []
Editing the JSON (a local copy) so that the开发者_StackOverflow社区 RelatedProducts array is null
instead of []
prevents the error, but I can't change the JSON being sent from the server.
Is there any way to get GSON to ignore empty arrays (or treat them as null)?
Are you sure that your class that Gson uses to put parsed data into contains an array of objects called RelatedProducts? Is RelatedProducts an array of objects or just a single object, so to speak?
精彩评论