我有這樣的JSON:GSON自定義字段Retrofit2解析 - Android電子
Class MyObject {
@SerializedName("attributes")
Attribues attributes;
@SerializedName("first")
String first;
@SerializedName("second")
String second;
@SerializedName("third")
String third;
}
而且
Class Attributes {
@SerializedName("date")
String date;
}
:
{
"attributes": {
"date": "2016-01-01"
},
"first": "05:33",
"second": "05:50",
"third": "07:22"
}
通常我們使用GSON改造解析器做這樣的事情來解析此JSON
但我想要做的是:
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的android庫,他們使用他們的轉換器,如果它可以在一種方式,我使用他們的轉換器,並使其作爲第二種解決方案。 – MBH
是的,我給你的鏈接正是關於retrofit2自定義json轉換器 – Divers