我正在尝试将以下 API 数据转换为 java 类。我特别感兴趣的是选择带有日期键的 timeSeriesDaily 字段和 openingStockPrice 字段。我尝试使用以下数据结构来捕获相关字段
public class AlphavantageData {
List<Map<String,TimeSeriesDaily>> timeSeriesDaily;
public List<Map<String, TimeSeriesDaily>> getTimeSeriesDaily() {
return timeSeriesDaily;
}
public void setTimeSeriesDaily(List<Map<String, TimeSeriesDaily>> timeSeriesDaily) {
this.timeSeriesDaily = timeSeriesDaily;
}
}
public class TimeSeriesDaily {
private Map<String,DayCloseStockPrice> dayStockPriceRecords;
public Map<String, DayCloseStockPrice> getDayStockPriceRecords() {
return dayStockPriceRecords;
}
public void setDayStockPriceRecords(Map<String, DayCloseStockPrice> dayStockPriceRecords) {
this.dayStockPriceRecords = dayStockPriceRecords;
}
}
public class DayCloseStockPrice {
private String closingStockPrice;
public String getClosingStockPrice() {
return closingStockPrice;
}
public void setClosingStockPrice(String closingStockPrice) {
this.closingStockPrice = closingStockPrice;
}
}
但是我不断收到以下 GSON 错误:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 10 column 10 path $.timeSeriesDaily[0]
如果有人能回答为什么这不起作用以及如何解决它,我将不胜感激。
30秒到达战场
茅侃侃
相关分类