0
轉換我有以下簡單的代碼matcherror例外,而試圖JSON字符串
val fileLine = s"""{"AP_details": [{"MAC_Address": "00:11:74:00:00:00"},{"MAC_Address": "00:11:74:00:00:00"},{"MAC_Address": "00:11:74:00:00:00"}]}
"""
val jsonAst = fileLine.parseJson
import APDetailsJsonProtocol._
jsonAst.convertTo[APDetails]
的轉換是在另一個文件中定義爲
封裝測試 進口spray.json._ 進口DefaultJsonProtocol._
case class APDetails(val mAPRadioOperatingParams:List[APDetail])
case class APDetail(val mac_id:String)
object APDetailsJsonProtocol extends DefaultJsonProtocol {
implicit val APDetailFormat = jsonFormat1(APDetail)
implicit object APDetailsJsonFormat extends RootJsonFormat[APDetails] {
def write(c: APDetails) = ???
def read(value: JsValue) = value.asJsObject.getFields("AP_Details") match
{
case Seq(jsv) => new APDetails(jsv.convertTo[List[APDetail]])
}
}
}
但是,我得到以下例外
Exception in thread "main" scala.MatchError: Vector() (of class scala.collection.immutable.Vector)
at test.APDetailsJsonProtocol$APDetailsJsonFormat$.read(APDetails.scala:13)
at test.APDetailsJsonProtocol$APDetailsJsonFormat$.read(APDetails.scala:11)
at spray.json.JsValue.convertTo(JsValue.scala:31)
at test.bootStrap.<init>(bootStrap.scala:25)
at test.TestApp$.delayedEndpoint$test$TestApp$1(TestApp.scala:10)
at test.TestApp$delayedInit$body.apply(TestApp.scala:4)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at test.TestApp$.main(TestApp.scala:4)
at test.TestApp.main(TestApp.scala)
我在做什麼錯? 最好的問候, Vishal
魔鬼在'Details' ... –