import play.api.libs.json._
val json: JsValue = Json.parse("""
{
"name" : "Independence",
"foundingFathers" : [ {
"name" : {
"first": "John",
"last": "Adams"
},
"country" : "United States"
}, {
"name" : {
"first": "Artur",
"last": "Mas"
},
"country" : "Catalonia"
} ]
}
""")
val lastNames = json \ "foundingFathers \ "name" \ "last"
// this does not work. it fails with: JsUndefined('last' is undefined on object: JsUndefined('name' is undefined on object: [{"name":{"first":"John","last":"Adams"},"country":"United States"},{"name":{"first":"Artur","last":"Mas"},"country":"Catalonia"}]))
// this does work, but there is too much boilerplate
val lastNames = (json \ "foundingFathers").as[List[JsObject]].map(_ \ "name" \ "last")
어떻게 그런 상용구없이 결과를 얻을 수 있습니까? 이스칼라로 배열하기위한 JsPath 재생 Json
한 줄이 너무 무 ch 상용구 ?? –
XML XPath에서 작동하는 첫 번째 접근 방식이 두 번째 방식보다 훨씬 간단하다고 생각하지 않습니까? 그리고 이것은 단지 사소한 예입니다. 더 복잡한 경로 질의가 있습니다 ... –