如何使用 Json Circe 在 Json 中访问 Json

问题描述

val json: String = """
  {
    "id": "c730433b-082c-4984-9d66-855c243266f0","name": "Foo","counts": [1,2,3],"values": {
      "bar": true,"baz": 100.001,"qux": ["a","b"]
    }
  }
"""

给定这个 json 字符串,我如何以 Json 的形式访问“值”?

我知道我们可以像这样访问其他字段:

val doc: Json = parse(json).getorElse(Json.Null)
val cursor: HCursor = doc.hcursor
val baz: Decoder.Result[Double] =
  cursor.downField("values").downField("baz").as[Double]

// baz: Decoder.Result[Double] = Right(100.001)

如何获取值以便结果为

一个包含 {bar: true,baz: 100.001,qux: ["a","b"]} 的 Json

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)