lift-json のscala 2.10 と互換性のある json-lift を使用していますが、extract メソッドにアクセスできないようです。この例のように:
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)
私の2つの質問は次のとおりです。
- json オブジェクトをケース クラスにマップするにはどうすればよいですか
- JString を通常の文字列に変換する方法。
更新: Lift の善良な人々が scala 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
}
}