Scala用JSON列表进行酸洗

时间:2015-05-23 09:54:53

标签: scala scala-pickling

我试图" unpickle"使用Scala-pickling的JSON结构如下:

{"id":1,"aList":[{"x":1}, {"x":2}]}

令人遗憾的是,使用以下代码进行取消修补:

import scala.pickling._, scala.pickling.Defaults._, json._

val jsonString="""{"id":1,"aList":[{"x":1}, {"x":2}]}"""

case class X(id:Int,aList:List[Y])
case class Y(x:Int)

jsonString.unpickle[X]

我得到以下异常:

scala.MatchError: [{"x" : 1.0}, {"x" : 2.0}] (of class scala.util.parsing.json.JSONArray)
at scala.pickling.json.JSONPickleReader$$anonfun$beginEntry$2.apply(JSONPickleFormat.scala:212)
at scala.pickling.json.JSONPickleReader$$anonfun$beginEntry$2.apply(JSONPickleFormat.scala:203)
at scala.pickling.PickleTools$class.withHints(Tools.scala:521)
at scala.pickling.json.JSONPickleReader.withHints(JSONPickleFormat.scala:170)
at scala.pickling.json.JSONPickleReader.beginEntry(JSONPickleFormat.scala:203)

是否可以在列表/集合中使用Scala-pickling?

0 个答案:

没有答案