此问题在此处已有答案:
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2(2个答案)
8个月前关门了。
我无法生成一个真正的代码来显示recyclerView中的所有元素...或者当我在RecyclerAdapter -holder.tvValueName.text = currentItem.AMD.Name
上使用此代码时,我只能显示1个元素,但当我想添加此代码的所有元素时-holder.tvValueName.text = currentItem.currencyModel.Name
-它不起作用...我已经尝试过更改一些类的类型,如val valute: Valute -to- val valute:List<Valute> or val currencyModel: CurrencyModel -to- val currencyModel: List<CurrencyModel>
,然后使用方法holder.tvValueName.text = currentItem.currencyModel.get(position).Name
获取值-但我得到错误与阵列...
如果有人有任何想法请帮助,提前感谢
第一个
整个JSON模型
data class Main(
val Date: String,
val PreviousDate: String,
val PreviousURL: String,
val Timestamp: String,
val Valute: Valute
)
data class CurrencyModel(
val CharCode: String,
val ID: String,
val Name: String,
val Nominal: Int,
val NumCode: String,
val Previous: Double,
val Value: Double
)
data class Valute(
val currencyModel: CurrencyModel,
val AMD: CurrencyModel,
val AUD: CurrencyModel,
val AZN: CurrencyModel,
val BGN: CurrencyModel,
val BRL: CurrencyModel,
val BYN: CurrencyModel,
val CAD: CurrencyModel,
val CHF: CurrencyModel,
val CNY: CurrencyModel,
val CZK: CurrencyModel,
val DKK: CurrencyModel,
val EUR: CurrencyModel,
val GBP: CurrencyModel,
val HKD: CurrencyModel,
val HUF: CurrencyModel,
val INR: CurrencyModel,
val JPY: CurrencyModel,
val KGS: CurrencyModel,
val KRW: CurrencyModel,
val KZT: CurrencyModel,
val MDL: CurrencyModel,
val NOK: CurrencyModel,
val PLN: CurrencyModel,
val RON: CurrencyModel,
val SEK: CurrencyModel,
val SGD: CurrencyModel,
val TJS: CurrencyModel,
val TMT: CurrencyModel,
val TRY: CurrencyModel,
val UAH: CurrencyModel,
val USD: CurrencyModel,
val UZS: CurrencyModel,
val XDR: CurrencyModel,
val ZAR: CurrencyModel
)
JSON格式
{
"Date": "2022-03-02T11:30:00+03:00",
"PreviousDate": "2022-03-01T11:30:00+03:00",
"PreviousURL": "\/\/www.cbr-xml-daily.ru\/archive\/2022\/03\/01\/daily_json.js",
"Timestamp": "2022-03-01T18:00:00+03:00",
"Valute": {
"AUD": {
"ID": "R01010",
"NumCode": "036",
"CharCode": "AUD",
"Nominal": 1,
"Name": "Австралийский доллар",
"Value": 66.7817,
"Previous": 67.3624
},
"AZN": {
"ID": "R01020A",
"NumCode": "944",
"CharCode": "AZN",
"Nominal": 1,
"Name": "Азербайджанский манат",
"Value": 53.9998,
"Previous": 55.067
},
"GBP": {
"ID": "R01035",
"NumCode": "826",
"CharCode": "GBP",
"Nominal": 1,
"Name": "Фунт стерлингов Соединенного королевства",
"Value": 123.1411,
"Previous": 125.0415
},
"AMD": {
"ID": "R01060",
"NumCode": "051",
"CharCode": "AMD",
"Nominal": 100,
"Name": "Армянских драмов",
"Value": 18.8196,
"Previous": 19.524
},
"BYN": {
"ID": "R01090B",
"NumCode": "933",
"CharCode": "BYN",
"Nominal": 1,
"Name": "Белорусский рубль",
"Value": 29.4765,
"Previous": 33.9264
},
"BGN": {
"ID": "R01100",
"NumCode": "975",
"CharCode": "BGN",
"Nominal": 1,
"Name": "Болгарский лев",
"Value": 52.5944,
"Previous": 53.4592
},
"BRL": {
"ID": "R01115",
"NumCode": "986",
"CharCode": "BRL",
"Nominal": 1,
"Name": "Бразильский реал",
"Value": 17.7795,
"Previous": 18.1182
},
"HUF": {
"ID": "R01135",
"NumCode": "348",
"CharCode": "HUF",
"Nominal": 100,
"Name": "Венгерских форинтов",
"Value": 27.7437,
"Previous": 28.0932
},
"HKD": {
"ID": "R01200",
"NumCode": "344",
"CharCode": "HKD",
"Nominal": 1,
"Name": "Гонконгский доллар",
"Value": 11.7413,
"Previous": 11.9737
},
"DKK": {
"ID": "R01215",
"NumCode": "208",
"CharCode": "DKK",
"Nominal": 1,
"Name": "Датская крона",
"Value": 13.8309,
"Previous": 14.0504
},
"USD": {
"ID": "R01235",
"NumCode": "840",
"CharCode": "USD",
"Nominal": 1,
"Name": "Доллар США",
"Value": 91.7457,
"Previous": 93.5589
},
"EUR": {
"ID": "R01239",
"NumCode": "978",
"CharCode": "EUR",
"Nominal": 1,
"Name": "Евро",
"Value": 102.9112,
"Previous": 104.4772
},
"INR": {
"ID": "R01270",
"NumCode": "356",
"CharCode": "INR",
"Nominal": 10,
"Name": "Индийских рупий",
"Value": 12.1817,
"Previous": 12.3927
},
"KZT": {
"ID": "R01335",
"NumCode": "398",
"CharCode": "KZT",
"Nominal": 100,
"Name": "Казахстанских тенге",
"Value": 18.6621,
"Previous": 18.8393
},
"CAD": {
"ID": "R01350",
"NumCode": "124",
"CharCode": "CAD",
"Nominal": 1,
"Name": "Канадский доллар",
"Value": 72.4346,
"Previous": 73.2646
},
"KGS": {
"ID": "R01370",
"NumCode": "417",
"CharCode": "KGS",
"Nominal": 10,
"Name": "Киргизских сомов",
"Value": 10.7936,
"Previous": 11.0069
},
"CNY": {
"ID": "R01375",
"NumCode": "156",
"CharCode": "CNY",
"Nominal": 1,
"Name": "Китайский юань",
"Value": 14.534,
"Previous": 14.8243
},
"MDL": {
"ID": "R01500",
"NumCode": "498",
"CharCode": "MDL",
"Nominal": 10,
"Name": "Молдавских леев",
"Value": 49.8618,
"Previous": 50.8472
},
"NOK": {
"ID": "R01535",
"NumCode": "578",
"CharCode": "NOK",
"Nominal": 1,
"Name": "Норвежская крона",
"Value": 10.4292,
"Previous": 10.4927
},
"PLN": {
"ID": "R01565",
"NumCode": "985",
"CharCode": "PLN",
"Nominal": 1,
"Name": "Польский злотый",
"Value": 21.9288,
"Previous": 22.2151
},
"RON": {
"ID": "R01585F",
"NumCode": "946",
"CharCode": "RON",
"Nominal": 1,
"Name": "Румынский лей",
"Value": 20.7899,
"Previous": 21.1342
},
"XDR": {
"ID": "R01589",
"NumCode": "960",
"CharCode": "XDR",
"Nominal": 1,
"Name": "СДР (специальные права заимствования)",
"Value": 127.9724,
"Previous": 130.4436
},
"SGD": {
"ID": "R01625",
"NumCode": "702",
"CharCode": "SGD",
"Nominal": 1,
"Name": "Сингапурский доллар",
"Value": 67.764,
"Previous": 68.8743
},
"TJS": {
"ID": "R01670",
"NumCode": "972",
"CharCode": "TJS",
"Nominal": 10,
"Name": "Таджикских сомони",
"Value": 81.2988,
"Previous": 82.8688
},
"TRY": {
"ID": "R01700J",
"NumCode": "949",
"CharCode": "TRY",
"Nominal": 10,
"Name": "Турецких лир",
"Value": 66.1464,
"Previous": 67.7806
},
"TMT": {
"ID": "R01710A",
"NumCode": "934",
"CharCode": "TMT",
"Nominal": 1,
"Name": "Новый туркменский манат",
"Value": 26.2506,
"Previous": 26.7694
},
"UZS": {
"ID": "R01717",
"NumCode": "860",
"CharCode": "UZS",
"Nominal": 10000,
"Name": "Узбекских сумов",
"Value": 84.384,
"Previous": 86.3067
},
"UAH": {
"ID": "R01720",
"NumCode": "980",
"CharCode": "UAH",
"Nominal": 10,
"Name": "Украинских гривен",
"Value": 30.4044,
"Previous": 31.0053
},
"CZK": {
"ID": "R01760",
"NumCode": "203",
"CharCode": "CZK",
"Nominal": 10,
"Name": "Чешских крон",
"Value": 41.0266,
"Previous": 41.8215
},
"SEK": {
"ID": "R01770",
"NumCode": "752",
"CharCode": "SEK",
"Nominal": 10,
"Name": "Шведских крон",
"Value": 96.7925,
"Previous": 98.1669
},
"CHF": {
"ID": "R01775",
"NumCode": "756",
"CharCode": "CHF",
"Nominal": 1,
"Name": "Швейцарский франк",
"Value": 100.2028,
"Previous": 101.0683
},
"ZAR": {
"ID": "R01810",
"NumCode": "710",
"CharCode": "ZAR",
"Nominal": 10,
"Name": "Южноафриканских рэндов",
"Value": 59.9571,
"Previous": 60.8375
},
"KRW": {
"ID": "R01815",
"NumCode": "410",
"CharCode": "KRW",
"Nominal": 1000,
"Name": "Вон Республики Корея",
"Value": 76.5619,
"Previous": 77.7626
},
"JPY": {
"ID": "R01820",
"NumCode": "392",
"CharCode": "JPY",
"Nominal": 100,
"Name": "Японских иен",
"Value": 79.7962,
"Previous": 80.9718
}
}
}
1条答案
按热度按时间cdmah0mi1#
在您的模型中更改
瓦尔值:值
至
瓦尔列表()
并将响应json从
“价值”:{“澳元”:{
至“价值”:[“澳元”:{
通过更改此项,您可以将Valute作为Arraylist获取,然后可以在适配器中加载数据