斯卡拉代码:
import net.liftweb.json._
case class Province(id: String, name: String, parentName: Option[String], parentId: Option[String])
case class ProvinceJson(provinceData: List[Province])
object Test extends Application {
val json = """ {
| "provinceData":
| [
| {
| "name":"hb",
| "parentName":null,
| "parentId":null,
| "id":"450"
| }
| ]
|}
| """.stripMargin
parse(json).extract[ProvinceJson]
}
当我运行此代码时,它报告编译错误:
could not find implicit value for parameter formats: net.liftweb.json.Formats
parse(json).extract[ProvinceJson]
^
not enough arguments for method extract: (implicit formats: net.liftweb.json.Formats, implicit mf: scala.reflect.Manifest[com.thoughtworks.sfexpress.sf_ws.ProvinceJson])com.thoughtworks.sfexpress.sf_ws.ProvinceJson.
Unspecified value parameters formats, mf.
parse(json).extract[ProvinceJson]
^
我想念什么吗?
最佳答案
您需要告诉解析器使用哪种格式,并为此解析器查找隐式参数。在您的代码中的某处添加它应该为您解决问题:
implicit val formats = net.liftweb.json.DefaultFormats
关于json - 无法使用lift-json将json解析为 `ProvinceJson`类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16827700/