簡體   English   中英

用Scala解析解析JSON

[英]Parsing JSON with Scala lift

我試圖解析其屬性名稱(點)中的特殊字符的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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM