contains
类似于play.api.libs.json.Json
val data=Map("id" -> "240190", "password" -> "password","email" -> "email@domain.com")
data.contains("email")//true
val info=Json.obj("id" -> "240190", "password" -> "password","email" -> "email@domain.com")
现在如何检查info
是否包含email
?
答案 0 :(得分:21)
info.keys.contains("email")
.keys
会为您提供一个包含键值的Set
,然后您可以调用contains
方法,我不确定是否有更直接的方法这样做。
答案 1 :(得分:6)
(info \ "email").asOpt[String].isEmpty
asOpt将返回Optional,我们可以进行isEmpty简单检查,这样做就可以了。
答案 2 :(得分:5)
(info \ "email").asOpt[String] match {
case Some(data) => println("here is the value for the key email represented by variable data" + data)
case None => println("email key is not found")
}