How to parse with GSON when identifier has space in name

前端 未结 2 1410
迷失自我
迷失自我 2020-12-03 15:49

How to parse with GSON when file looks like this

{
    \"Person Id\":\"test\",
    \"Last Name\": \"test\",
    \"First Name\":\"test\"
}

2条回答
  •  [愿得一人]
    2020-12-03 16:28

    While still using GSON you can do this by adding an annotation. For instance:

    class Person{
        @SerializedName("Person Id") public String PersonId;
        @SerializedName("Last Name") public String LastName;
        @SerializedName("First Name") public String FirstName;
    }
    

    You can find more details in the GSON documentation: https://sites.google.com/site/gson/gson-user-guide#TOC-JSON-Field-Naming-Support

提交回复
热议问题