0
我有這樣的JSON數據模型映射與GSON返回null
{
"Meta Data": {
"1: Symbol": "stock",
"2: Indicator": "SMA",
"3: Last Refreshed": "2017-07-25 09:50:00",
"4: Interval": "daily",
"5: Time Period": 3,
"6: Series Type": "open",
"7: Time Zone": "US/Eastern"
},
"Technical Analysis: SMA": {
"2017-07-25 09:50:00": {
"SMA": "266.6264"
},
"2017-07-24": {
"SMA": "265.9137"
},
"2017-07-21": {
"SMA": "265.3237"
}
}}
,我已經爲了映射這些類獲取模型GSON庫(股票,元數據,TechAnalysis,DayValue直接填充):
public class Stock {
private MetaData metaData;
private TechAnalysis tech;
public MetaData getMetaData() {
return metaData;
}
public void setMetaData(MetaData metaData) {
this.metaData = metaData;
}
public TechAnalysis getTech() {
return tech;
}
public void setTech(TechAnalysis tech) {
this.tech = tech;
}}
public class MetaData {
private String symbol;
private String indicator;
private Date lastRefreshed;
private String interval;
private Integer period;
private String zone;
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getIndicator() {
return indicator;
}
public void setIndicator(String indicator) {
this.indicator = indicator;
}
public Date getLastRefreshed() {
return lastRefreshed;
}
public void setLastRefreshed(Date lastRefreshed) {
this.lastRefreshed = lastRefreshed;
}
public String getInterval() {
return interval;
}
public void setInterval(String interval) {
this.interval = interval;
}
public Integer getPeriod() {
return period;
}
public void setPeriod(Integer period) {
this.period = period;
}
public String getZone() {
return zone;
}
public void setZone(String zone) {
this.zone = zone;
}}
public class TechAnalysis {
private List<DayValue> dayValuesList;
public List<DayValue> getDayValuesList() {
return dayValuesList;
}
public void setDayValuesList(List<DayValue> dayValuesList) {
this.dayValuesList = dayValuesList;
}}
public class DayValue {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}}
我的代碼,以地圖上的JSON響應的模式是這樣的:
public static Stock getStock(String json){
Gson gson = new Gson();
return gson.fromJson(json, Stock.class);
}
但庫存對象返回始終爲空
是你的參數'json'一個有效的stringify json'格式'?覈實。 – Beginner