【发布时间】:2015-03-15 07:17:01
【问题描述】:
{
"location":{
"residents":[{
"renting":[{
"name":"John Doe"
"pets":"2"
},{
"name":"Jane Smith"
"pets":"2"
}]
}]
}
}
我可以用这个成功遍历位置-
val json = ...
val rentReads = (__ \ 'location).read[String]
val rentResult = json.validate[String](rentReads)
rentResult match {
case s: JsSuccess[String] => Ok(s.get)
case e: JsError => Ok("Errors: " + JsError.toFlatJson(e).toString())
}
根据文档,我应该可以做这样的事情-
val skillReads = ((__ \ 'location) \ 'residents)(0).read[String]
但它会导致以下错误-
Errors: {"obj.VariationResultsWrapper.VariationResultSets[0]":[{"msg":"error.path.missing","args":[]}]}
此时我只是想了解如何仅从“出租”中返回值。最后,我想将该结果映射到一个案例类。
【问题讨论】:
标签: json scala playframework playframework-2.0 scala-2.10