我正与来自谷歌-API客户端在YouTube JSON:
i'm working with the youtube json from google-api-client :
{
"apiVersion": "2.0",
"data": {
"updated": "2011-01-05T13:48:33.146Z",
"totalItems": 4,
"startIndex": 1,
"itemsPerPage": 1,
"items": [
{
"id": "YfUzMkAlOBI",
"uploaded": "2010-12-29T16:50:47.000Z",
"updated": "2010-12-29T16:50:47.000Z",
"uploader": "devandroidcs",
"category": "Entertainment",
"title": "Teste 2",
"description": "Description do teste2",
"tags": [
"mobile"
],
"thumbnail": {
"sqDefault": "https://m.xsw88.com/allimgs/daicuo/20230906/1918.png.jpg",
"hqDefault": "https://m.xsw88.com/allimgs/daicuo/20230906/1919.png.jpg"
},
"player": {
"default": "http://www.youtube.com/watch?v\u003dYfUzMkAlOBI&feature\u003dyoutube_gdata_player",
"mobile": "http://m.youtube.com/details?v\u003dYfUzMkAlOBI"
}
.
.
.
}
在这一点上,我应该创建一个名为默认情况下,在我的解析Java类中的字段名。 已经完成与其他领域的这一解析工作,问题是,默认情况下是 私人java的名称,所以我不能把一个变量的默认。
at this point i should create a field name called default at my parse java class. Already done this parse work with the other fields , the problem is that , default is a private java name so i can't call a variable default .
我如何管理的?
我相信,你的答案就在的 JSON字段命名支持:
I believe your answer lies in the JSON Field Naming Support:
GSON支持一些pre定义字段 命名策略转换的 标准的Java字段名(即骆驼 首先是较低的情况下套管的名字 ---sampleFieldNameInJava),以一个JSON字段名(即 sample_field_name_in_java或 SampleFieldNameInJava)。
Gson supports some pre-defined field naming policies to convert the standard Java field names (i.e. camel cased names starting with lower case --- "sampleFieldNameInJava") to a Json field name (i.e. sample_field_name_in_java or SampleFieldNameInJava).
例如,参见下面的例子:
See for instance the following example:
private class SomeObject {
@SerializedName("custom_naming") private final String someField;
private final String someOtherField;
public SomeObject(String a, String b) {
this.someField = a;
this.someOtherField = b;
}
}
所以,你应该能够定义字段映射到这样的默认值:
So you should be able to define the field mapping to the default value like this:
@SerializedName("default")
private final String someOtherNameThanDefault;