0

我正在尝试通过 API 显示 JSON 对象,但同时收到一条错误消息。

这是我写的方法:

public MarketDataListLevel1 getMarketDataTicker() {
    try {
        MarketDataListLevel1 md = CS.getMarketDataTicker();
        log.info(md.toString());
        return md;
     }
     catch ( Exception e) {
         e.printStackTrace();
         return null;
     }
}

其中 CS 是处理来自 URL 的 JSON 数据的对象。

出于某种原因,当我调用该方法时,我得到了我想要的精确输出,但我也得到了跟随它的这些额外的错误消息,我不确定为什么。任何帮助,将不胜感激。

14:52:55.265 [default] [main] ERROR si.mazi.rescu.JSONUtils - Error unmarshalling from 
json: {"Bid":{"Price":183.25,"Size":0.0,"ExchangeID":"SMART","timeStamp":0},"Ask":{"Price":185.0,"Size":0.0,"ExchangeID":"SMART","timeStamp":0},"Last":{"Price":182.44,"Size":4.0,"ExchangeID":"SMART","timeStamp":0}} 
java.lang.RuntimeException: Problem getting JSON object
at (Skipped all these logs)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize      instance of com.xeiam.xchange.cs.dto.MarketData[] out of START_OBJECT token
at [Source: java.io.StringReader@5069bb01; line: 1, column: 2]

这是我想要返回的数据格式:

{"Bid":{"Price":204.08,"Size":1.0,"ExchangeID":"SMART","timeStamp":0},
 "Ask":{"Price":203.2,"Size":0.0,"ExchangeID":"SMART","timeStamp":0},
 "Last":{"Price":204.64,"Size":2.0,"ExchangeID":"SMART","timeStamp":0}}

它似乎正在实现这一点。

MarketDataLevel1 定义为:

public class MarketDataListLevel1 {
public MarketData[] MarketDataListLast;
public MarketData[] MarketDataListBid;
public MarketData[] MarketDataListAsk;
public MarketDataListLevel1(@JsonProperty("Bid") MarketData[] MarketDataListBid,@JsonProperty("Ask") MarketData[] MarketDataListAsk,@JsonProperty("Last") MarketData[] MarketDataListLast) {
    this.MarketDataListBid = MarketDataListBid;
    this.MarketDataListAsk = MarketDataListAsk;
    this.MarketDataListLast = MarketDataListLast;
}

和 MarketData 作为

public class MarketData {
public BigDecimal Price;                    
public BigDecimal Size;                 
public String ExchangeID;                  
public long timeStamp;

public MarketData(
        @JsonProperty("Price") BigDecimal Price,
        @JsonProperty("Size") BigDecimal Size,
        @JsonProperty("ExchangeID") String ExchangeID,
        @JsonProperty("timeStamp") long timeStamp)          {

    this.Price = Price;
    this.Size = Size;
    this.ExchangeID = ExchangeID;
    this.timeStamp = timeStamp;
}

}

4

0 回答 0