无法从字符串中反序列化“java.lang.Long”类型的值,而不是有效的 Long 值

Cannot deserialize value of type `java.lang.Long` from String not a valid Long value

提问人:Ömer 提问时间:7/4/2023 最后编辑:Ömer 更新时间:7/29/2023 访问量:364

问:

我有一个活动,该活动在我的 Coins 类中运行一个函数。我正在尝试将下面的代码转换为 Kotlin 并运行它。

  fun timeRequest() {
    GlobalScope.launch(Dispatchers.IO) {
        val tickerStatistics = client.get24HrPriceStatistics("NEOETH")
        withContext(Dispatchers.Main) {
            println(tickerStatistics.lastPrice)
        }
    }
}

但是我有一个错误,如下所示:

Cannot deserialize value of type `java.lang.Long` from String "0.09700000": not a valid Long value

我想这是关于选角问题。即使我尝试转换

override fun doInBackground(vararg params: Void?): Long

override fun doInBackground(vararg params: Void?): Float

它什么也改变不了。

theLastTimevar 很长,但错误指向下面的那行

var theLastTime = client.getCandlestickBars("NEOETH", CandlestickInterval.WEEKLY)[0].openTime

返回类型如下

[Candlestick[openTime=1506297600000,open=0.09700000,high=0.12000100,low=0.05500000,close=0.11986900,volume=25709.37000000,closeTime=1506902399999,quoteAssetVolume=2649.80091051,numberOfTrades=2435,takerBuyBaseAssetVolume=10520.59000000,takerBuyQuoteAssetVolume=1101.94985388], ...] 

您可以在此处检查更多内容

CandleStick 库位于下方

package com.binance.api.client.domain.market;

import com.binance.api.client.constant.BinanceApiConstants;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import org.apache.commons.lang3.builder.ToStringBuilder;

@JsonFormat(
    shape = Shape.ARRAY
)
@JsonPropertyOrder
@JsonIgnoreProperties(
    ignoreUnknown = true
)
public class Candlestick {
    private Long openTime;
    private String open;
    private String high;
    private String low;
    private String close;
    private String volume;
    private Long closeTime;
    private String quoteAssetVolume;
    private Long numberOfTrades;
    private String takerBuyBaseAssetVolume;
    private String takerBuyQuoteAssetVolume;

    public Candlestick() {
    }

    public Long getOpenTime() {
        return this.openTime;
    }

    public void setOpenTime(Long openTime) {
        this.openTime = openTime;
    }

    public String getOpen() {
        return this.open;
    }

    public void setOpen(String open) {
        this.open = open;
    }

    public String getHigh() {
        return this.high;
    }

    public void setHigh(String high) {
        this.high = high;
    }

    public String getLow() {
        return this.low;
    }

    public void setLow(String low) {
        this.low = low;
    }

    public String getClose() {
        return this.close;
    }

    public void setClose(String close) {
        this.close = close;
    }

    public String getVolume() {
        return this.volume;
    }

    public void setVolume(String volume) {
        this.volume = volume;
    }

    public Long getCloseTime() {
        return this.closeTime;
    }

    public void setCloseTime(Long closeTime) {
        this.closeTime = closeTime;
    }

    public String getQuoteAssetVolume() {
        return this.quoteAssetVolume;
    }

    public void setQuoteAssetVolume(String quoteAssetVolume) {
        this.quoteAssetVolume = quoteAssetVolume;
    }

    public Long getNumberOfTrades() {
        return this.numberOfTrades;
    }

    public void setNumberOfTrades(Long numberOfTrades) {
        this.numberOfTrades = numberOfTrades;
    }

    public String getTakerBuyBaseAssetVolume() {
        return this.takerBuyBaseAssetVolume;
    }

    public void setTakerBuyBaseAssetVolume(String takerBuyBaseAssetVolume) {
        this.takerBuyBaseAssetVolume = takerBuyBaseAssetVolume;
    }

    public String getTakerBuyQuoteAssetVolume() {
        return this.takerBuyQuoteAssetVolume;
    }

    public void setTakerBuyQuoteAssetVolume(String takerBuyQuoteAssetVolume) {
        this.takerBuyQuoteAssetVolume = takerBuyQuoteAssetVolume;
    }

    public String toString() {
        return (new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)).append("openTime", this.openTime).append("open", this.open).append("high", this.high).append("low", this.low).append("close", this.close).append("volume", this.volume).append("closeTime", this.closeTime).append("quoteAssetVolume", this.quoteAssetVolume).append("numberOfTrades", this.numberOfTrades).append("takerBuyBaseAssetVolume", this.takerBuyBaseAssetVolume).append("takerBuyQuoteAssetVolume", this.takerBuyQuoteAssetVolume).toString();
    }
}

我怎样才能得到这个openTime值而不会出错?

Android Kotlin 铸造 币安

评论

0赞 Eselfar 7/5/2023
A 是一个长整数值。长整型值的格式为:“123L”。如果您有小数,则它不是 .因此,您应该改用,或者将非 Long 的值视为无效,并引发自定义异常或返回默认值(如LongLongDouble0)
0赞 Ömer 7/5/2023
@Eselfar我也尝试了双倍。但不幸的是,同样的结果
0赞 Eselfar 7/5/2023
从何而来?"0.09700000"
0赞 Ömer 7/6/2023
@Eselfar我也尝试了其他属性。我猜是其中之一。在烛台列表中。
0赞 Ömer 7/6/2023
@Eselfar烛台列表中的开盘价为 0.09700000。

答: 暂无答案