【发布时间】:2021-11-05 11:23:47
【问题描述】:
我对 android 和 GSON 库非常陌生,但在尝试获取 GSON 模型子类时遇到了问题。
我使用预定义的 OKhttp Profiler 构建器创建了一个带有子类 Values 的 GSON 对象 Indicators 并获取方法:
import java.util.List;
import com.google.gson.annotations.SerializedName;
public class Indicators {
@SerializedName("indicator")
public Indicator indicator;
public static class Values {
@SerializedName("value")
private static double value;
@SerializedName("datetime")
private static String datetime;
@SerializedName("datetime_utc")
private static String datetimeUtc;
@SerializedName("tz_time")
private static String tzTime;
@SerializedName("geo_id")
private static int geoId;
@SerializedName("geo_name")
private static String geoName;
public static double getValue() {
return value;
}
public static String getDatetime() {
return datetime;
}
public static String getDatetimeUtc() {
return datetimeUtc;
}
public static String getTzTime() {
return tzTime;
}
public static int getGeoId() {
return geoId;
}
public static String getGeoName() {
return geoName;
}
}
}
我一直在获取价值:
public class HandelJSON {
public static void GSONModel(String JSON) {
Gson gson = new Gson();
Indicators IndicatorsModel = gson.fromJson(JSON, Indicators.class);
// ... Here I am missed
}
}
如何调用子类子方法?我试过IndicatorsModel.Values.getValue();,但我得到“预期的类或包”
【问题讨论】:
-
为什么
Values是一个静态类?