在使用GSon的android中,@SerializedName注解的基本用途是什么 [英] what is the basic purpose of @SerializedName annotation in android using GSon
问题描述
任何人都可以告诉我使用 GSON
$ b 给android @SerializedName 注释的基本用途。我有一个不同的例子。我已经在不同的网站上进行了检查,但我无法理解它的主要用途。
public class Person {
@SerializedName(name)
private String personName;
@SerializedName(bd)
private String birthDate;
这个类有两个字段,代表人名和出生一个人的日期。这些字段使用 @SerializedName 注释进行注释。此批注的参数(值)是序列化
和反序列化
对象时要使用的名称。例如,Java字段 personName 在JSON中表示为 name 。
JSON示例
{
name:chintan,
bd:01-01-1990
}
can anyone tell me what is the basic purpose of @SerializedName annotation in android using GSON
Give me some different example. I have checked in different website but I can't understand what is main purpose of using it.
解决方案 Java class example,
public class Person {
@SerializedName("name")
private String personName;
@SerializedName("bd")
private String birthDate;
}
This class has two fields that represent the person name and birth date of a person. These fields are annotated with the @SerializedName annotation. The parameter (value) of this annotation is the name to be used when serialising
and deserialising
objects. For example, the Java field personName is represented as name in JSON.
JSON Example,
{
"name":"chintan",
"bd":"01-01-1990"
}
这篇关于在使用GSon的android中,@SerializedName注解的基本用途是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!