Существуют различные способы сделать это, например:
import play.api.libs.json._
case class View(width: String, height: String, code: String, href: String)
object View {
implicit val viewFormat: Format[View] = Json.format[View]
}
case class MyJsonObject(view: Seq[View])
object MyJsonObject {
implicit val myJsonObjectFormat: Format[MyJsonObject] = Json.format[MyJsonObject]
}
val s = """{
"view": [{
"width": "2100",
"height": "1575",
"code": "1",
"href": "1.png"
},
{
"width": "320",
"height": "240",
"code": "2",
"href": "2.png"
},
{
"width": "2100",
"height": "1575",
"code": "2",
"href": "2.png"
},
{
"width": "2100",
"height": "1575",
"code": "3",
"href": "4.png"
}
]
}"""
def findMyHref(width: String, height: String, code: String): Option[String] = {
for {
myJsonObject <- Json.parse(s).asOpt[MyJsonObject]
myView <- myJsonObject.view.find(v => v.width == width && v.height == height && v.code == code)
} yield {
myView.href
}
}
findMyHref("2100", "1575", "2") //Some(2.png)
findMyHref("1", "2", "3") //None
Вот документация .