我需要帮助来使用 playJson 将 json 字符串解析为 scala 类
我写了一个格式化程序,但我不知道如何处理嵌套数组。
文档案例类在哪里
case class Document(content: String, score: Double, size: Int, path:String)
和格式化程序
implicit val similarHashFormatter: Format[SimilarHash] = (
((__ \ "hits" \ "hits" \\ "fields")(0) \ "content_hash")(0).format[String] and
(__ \ "hits" \ "hits" \\ "_score").format[Double] and
((__ \ "hits" \ "hits" \\ "fields")(0) \ "ast_size")(0).format[Int] and
((__ \ "hits" \ "hits" \\ "fields")(0) \ "path")(0).format[String]
) (SimilarHash.apply, unlift(SimilarHash.unapply))
这是我的源 json
{
"hits": {
"hits": [
{
"score": 1.5204661,
"fields": {
"size": [
557645
],
"path": [
"/user/ubuntu/app
],
"content": [
"images"
]
}
},
{
"score": 1.5199462,
"fields": {
"size": [
556835
],
"path": [
"/user/ubuntu/app
],
"content": [
"documents"
]
}
}
]
}
}
任何想法 ?