开发者

Gson error when parsing empty arrays [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

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 question

I'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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜