在使用GSon的android中,@SerializedName注解的基本用途是什么 [英] what is the basic purpose of @SerializedName annotation in android using GSon

查看:486
本文介绍了在使用GSon的android中,@SerializedName注解的基本用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我使用 GSON
$ b 给android @SerializedName 注释的基本用途。我有一个不同的例子。我已经在不同的网站上进行了检查,但我无法理解它的主要用途。

/ p>

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆