Parse JSON using gson with key name containing period (.)

前端 未结 1 477
眼角桃花
眼角桃花 2021-01-23 22:03
{
   \"data.url\" : \"http://dev.com\",
   \"value\": [
       {
         \"color\": \"red\"
          \"shape\": \"rect\"
       },
       {
          \"color\": \"blue         


        
相关标签:
1条回答
  • 2021-01-23 22:08

    Because Java doesn't allow . in a variable name, you need to use the @SerializedName annotation on that field in your class:

    public class MyPojo {
    
        @SerializedName("data.url")
        private String dataUrl;
        ...
    
    }
    
    0 讨论(0)
提交回复
热议问题