scala案例类期望使用List [Objects],但json值以字符串形式出现

问题描述 投票:0回答:1

我有一个具有以下结构的json:

{
"name":"mark",
"address": "\r\n[\r\n{\r\n\"line1\":\"careve\",\r\n\"line2\":\"roxn\",\r\n\"line3\":\"asdef\"\r\n},\r\n{\r\n\"line1\":\"wedf\",\r\n\"line2\":\"aswd\",\r\n\"line3\":\"xsqa\"\r\n}\r\n]\r\n"
}

转义后,我得到了:

{
  "name": "mark",
  "address": " [ { "line1":"careve", "line2":"roxn", "line3":"asdef" }, { "line1":"wedf", "line2":"aswd", "line3":"xsqa" } ] "
}

案例类别:

case class Details(name:String,address:List[Address])
case class Address(line1:String,line2:String,line3:String)

我知道address期望一个List[Address],但是它以字符串形式出现,因此也不会因为我得到明显的错误而强制转换

Exception in thread "main" net.liftweb.json.MappingException: No usable value for address
Expected collection but got JString(
[
{
"line1":"careve",
"line2":"roxn",
"line3":"asdef"
},
{
"line1":"wedf",
"line2":"aswd",
"line3":"xsqa"
}
]
) for root JString(

如何将其解析为案例类?

scala lift-json
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.