0
0

https://beonmax.com/courses/kotlin/nastraivaem-viewmodel . Переденный мной обьект не совпадает с первым параметрам метода fromJson

private fun getListOfCoinPriceInfo(coinPriceInfoRawData: CoinPriceInfoRawData): List<CoinPriceInfo> {
        val result = ArrayList<CoinPriceInfo>()
        val jsonObject = coinPriceInfoRawData.coinTypeListData
        if (jsonObject == null) return result
        val coinsKeySet = jsonObject.keys()
        for (coinKey in coinsKeySet) {
            val currencyJson = jsonObject.getJSONObject(coinKey)
            val currencyKeySet = currencyJson.keys()
            for (currencyKey in currencyKeySet) {
                val coinPriceInfo: CoinPriceInfo = Gson().fromJson<CoinPriceInfo>(
                    currencyJson.getJSONObject(currencyKey),
                    CoinPriceInfo::class.java
                )
                result.add(coinPriceInfo)
            }
        }
        return result
    }

Sheikh Bahromov
1 year ago






Все нашел ответ. Оказывается проблема была в import ах

import com.google.gson.JsonObject // Правильный импорт

import org.json.JSONObject        // Неправильный импорт

import com.google.gson.annotations.Expose

import com.google.gson.annotations.SerializedName


data class CoinPriceInfoRawData (

    @SerializedName("RAW")
    @Expose
    val  coinListRawData: JsonObject
)

Sheikh Bahromov
1 year ago

Один ответ