我正在使用与来自lift-json的scala 2.10兼容的json-lift,但我似乎无法访问提取方法。像这样的例子:json-lift提取方法无法访问
import net.liftweb.json._
object testobject {
case class process(process_id:Int,job_id:Int ,command:String, exception:String)
def main(args: Array[String]) {
val json = parse("""
{
"process_id": "2",
"job_id": "540",
"command": "update",
"exception": "0"
}
""")
json.extract[process] // produces an error
}
}
现在班里有动态的分析,例如以下不会产生(甜)任何错误:
json.process_id // will produce JString(2)
我的两个问题是:
- 如何可以将json对象映射到我的案例类
- 如何将JString转换为常规字符串。
更新: 善良的人在lift创造了斯卡拉2.10.0升级......这样你就可以刚刚从他们的下载。无需任何工作。
import net.liftweb.json._
object testobject {
case class process(process_id:Int,job_id:Int ,command:String, exception:String)
def main(args: Array[String]) {
val json = parse("""
{
"process_id": "2",
"job_id": "540",
"command": "update",
"exception": "0"
}
""")
val p = json.extract[process] // maps the json object to the process case class
println(p.job_id) // will print 540
}
}
谢谢你的帮助。这当然给了我一些想法。 – CruncherBigData