私はこのJSONを持っている:Retrofit2で解析するGSONカスタムフィールドは - アンドロイド
{
"attributes": {
"date": "2016-01-01"
},
"first": "05:33",
"second": "05:50",
"third": "07:22"
}
通常、我々はGsonの改造パーサーを使用して、このJSONを解析するために、このような何かを:
Class MyObject {
@SerializedName("attributes")
Attribues attributes;
@SerializedName("first")
String first;
@SerializedName("second")
String second;
@SerializedName("third")
String third;
}
そして
Class Attributes {
@SerializedName("date")
String date;
}
私がやりたいことはこれです:
Class MyObject {
// I want date to be here and ignoring the attributes key <---
String date;
@SerializedName("first")
String first;
@SerializedName("second")
String second;
@SerializedName("third")
String third;
}
どうすればこのことができますか? GSonについての質問の
を使用しています。この回答を見てください - http://stackoverflow.com/questions/35502079/custom-converter-for-retrofit-2 – Divers
しかし、私はretrofitと呼ばれるアンドロイド用のライブラリを使用し、可能であればコンバータを使用します私はコンバータを使用し、それを第2の解決策として使用する方法です。 – MBH
はい、私があなたに与えたリンクはちょうどretrofit2のカスタムJSONコンバータについてのものです – Divers