How to read JSON variable that use number for its name, with GSON

后端 未结 4 1478
暗喜
暗喜 2021-01-16 12:06

First, im a beginner in GSON so please bear with me.

I tried to read a JSON from this url :

https://gdata.youtube.com/feeds/api/videos?author=radityad

4条回答
  •  醉话见心
    2021-01-16 13:02

    It's old but maybe someone needs it still...

    To serialize properties which name is just Integer just make model class like:

    Json:

    {
      "name": "foo",
      "1": "value one",
      "2": "value two",
      "3": "value three"
    }
    

    Java:

    import com.google.gson.annotations.SerializedName;
    
    public class Foo {
    
       private String name;
    
       @SerializedName("1")
       private String one;
    
       @SerializedName("2")
       private String two;
    
       @SerializedName("3")
       private String three;
    
       // standard getter & setters bellow...
    
    }
    

提交回复
热议问题