我有一个免费的 api,用于使用 json 进行货币跟踪: api.coinmarketcap 我需要使用 Gson 库将这个 json 反序列化为我的复合 java 对象。这是我的模型对象:
public class Quote {
@SerializedName("quotes")
private String mName;
@SerializedName("price")
private double mPrice;
public Quote(String name, double price) {
mName = name;
mPrice = price;
}
public String getName() {
return mName;
}
public double getPrice() {
return mPrice;
}
}
和:
public class Currency {
private int mId;
private String mSymbol;
private byte mRank;
private String mWebsiteSlug;
private int mMaxSupply;
private Quote mQuote;
public Currency(int id, String symbol, byte rank, String websiteSlug, int maxSupply) {
mId = id;
mSymbol = symbol;
mRank = rank;
mWebsiteSlug = websiteSlug;
mMaxSupply = maxSupply;
}
public int getId() {
return mId;
}
public String getSymbol() {
return mSymbol;
}
public byte getRank() {
return mRank;
}
public String getWebsiteSlug() {
return mWebsiteSlug;
}
public int getMaxSupply() {
return mMaxSupply;
}
public Quote getQuote() {
return mQuote;
}
}
我不能用这种嵌套反序列化。
绝地无双
至尊宝的传说
相关分类