我正在尝试解析在其属性名称(点)中包含特殊字符的 json 字符串。
这就是我正在尝试的:
//Json parser objects
case class SolrDoc(`rdf.about`:String, `dc.title`:List[String],
`dc.creator`:List[String], `dc.dateCopyrighted`:List[Int],
`dc.publisher`:List[String], `dc.type` :String)
case class SolrResponse(numFound:String, start:String, docs: List[SolrDoc])
val req = url("http://localhost:8983/solr/select") <<? Map("q" -> q)
var search_result = http(req ># { json => (json \ "response") })
var response = search_result.extract[SolrResponse]
即使我的 json 字符串包含所有字段的值,这也是我收到的错误:
Message: net.liftweb.json.MappingException: No usable value for docs
No usable value for rdf$u002Eabout
Did not find value which can be converted into java.lang.String
我怀疑它与名字上的点有关,但到目前为止我没能成功。
谢谢!
这些是我的 LiftProject.scala 文件的摘录:
"net.databinder" % "dispatch-http_2.8.1" % "0.8.6",
"net.databinder" % "dispatch-http-json_2.8.1" % "0.8.6",
"net.databinder" % "dispatch-lift-json_2.8.1" % "0.8.6"
最佳答案
名称中的点应该不是问题。这是 lift-json-2.4-M4
scala> val json = """ {"first.name":"joe"} """
scala> parse(json).extract[Person]
res0: Person = Person(joe)
在哪里
case class Person(`first.name`: String)
关于json - 使用 Scala lift 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8062032/