@SerializedName 注解可以用来将字段序列化为不同的名称,而不是实际的字段名称。我们可以将预期的序列化名称作为注解属性提供,Gson可以确保使用提供的名称读取或写入字段。语法@Retention(value=RUNTIME) @Target(value={FIELD, METHOD}) public @interface SerializedName示例import com.google.gson.*; import com.google.gson.annotations.*; public class SerializedNameTest { public static void main(String args[]) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); Person person = new Person(115, "Raja Ramesh", "Hyderabad"); String jsonStr = gson.toJson(person); System.out.println(jsonStr); } } // Person 类 class ... 阅读更多