Why does Gson fromJson throw a JsonSyntaxException: Expected BEGIN_OBJECT but was BEGIN_ARRAY?

后端 未结 2 1702
栀梦
栀梦 2020-11-21 12:00

(This post is meant to be a canonical question with a sample answer provided below.)


I\'m trying to deserialize some JSON content into a custom POJO type with

2条回答
  •  一个人的身影
    2020-11-21 12:21

    class Pojo {
      NestedPojo nestedPojo;
    }
    

    in your json you have an array of nestedPojo so either you change the code

      NestedPojo[] nestedPojo;
    

    or you change the json string

    String json = "{\"nestedPojo\":{\"name\":null, \"value\":42}}";
    

提交回复
热议问题