简体   繁体   中英

parse Json String using scala.util.parsing.json

I have a json string and I wast to be able to parse it to get the 'key' values.

jsonString = {"id":2279,
"name":"Test",
"description":null,
"tags":[],
"keys":[{
"key":"WI1MX6XAWSY03X8Y",
"flag":true},
{"key":"BK2Q18T8RSN6VODR",
"flag":false}]}

I want to be able to parse this string and get values for both the keys.

Currently I'm doing:

val details = JSON.parseFull(jsonString)
val keys = details.get.asInstanceOf[Map[String, Any]]("keys")
println(keys)

keys here is:

List(Map(key -> 3JP11GJ5OOGOVV5N, flag -> true), Map(key -> F49M347FOHYKBT9, flag -> false))

Please let me know how i can get both the 'key' values.

实际上没有任何与JSON相关的内容,您只需要这样做:

val keysValues = key.map(k => k("key"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM