我想将接收字符串转换为我的实体,但我有这个例外:com.fasterxml.Jackson.databind.exc.MismatchedInputException:无法从数组值(标记JsonToken.START_ARRAY
)中解析fonbet.parser.models.childs.AllScore
类型的值我做错了什么?我应该用什么对象来实现这个JSON?
我接收到JSON字符串,其中包含对象:
"liveEventInfos": [
{
"eventId": 42183931,
"timer": "45:00",
"timerSeconds": 2700,
"timerDirection": 0,
"scoreFunction": "Football",
"scoreComment": "(1-2) https://www.youtube.com/watch v=TDkuCAfGoLg",
"scoreCommentTail": "https://www.youtube.com/watch?v=TDkuCAfGoLg",
"scores": [
[
{
"c1": "1",
"c2": "2"
}
],
[
{
"c1": "1",
"c2": "2",
"title": "тайм"
},
{
"c1": "0",
"c2": "0",
"title": "тайм"
}
]
],
"subscores": []
}
]
我所拥有的:
我有这个JSON部分的实体:
data class LiveEventInfo(
var eventId: Long?,
var timer: String?,
var timerSeconds: Long?,
var timerDirection: Long?,
var scoreFunction: String?,
var scoreComment: String?,
var scoreCommentTail: String?,
var scores: List<AllScore>?
)
AllScore:
data class AllScore(
val matchSore: HashMap<String, String>,
val timeScore: HashMap<String, String>
)
1条答案
按热度按时间py49o6xq1#
几件事
AllScore
是一个有两个字段matchSore
,timeScore
的对象,这两个字段在JSON中没有引用。scores
下的外部数组中有1个或2个数组。解析器应该如何实现这一点?第一个是matchSore
吗?如果是2,那么它是matchSore
和timeScore
?1.您缺少
subscores
1.您提供的JSON缺少外部
{
}
1.通常,在这种情况下,您应该有一个 Package 器对象来读取。
下面的代码可以工作,你应该能够从这一点得到一些工作: