val json = Json.parse(jsonString)
(json \ "theme" \ "structure" \ "layers")layers的json键是一个对象,它的键按如下顺序编号
{0: {}, 1: {}, 2: {}}我不知道有多少个键,也不知道键的模式,只有我的键在每个键中尝试检索的模式存在。
我可以使用以下命令访问它们
(json \ "theme" \ "structure" \ "layers" \ "0" \ "mykey")但由于有时有数百个层,我需要能够以编程方式遍历它们,并检查每个层中"mykey“的值。
发布于 2017-08-24 22:45:27
(json \ "theme" \ "structure" \ "layers")
.get
.as[Map[String, JsObject]]
.map(x => (x._1, (x._2 \ "mykey").get.as[String]))这对我很有效。
https://stackoverflow.com/questions/45864397
复制相似问题