我正在尝试验证props:List<String>
值是否存在message:String
并返回值是真还是假。
fun main() {
val message = """
{
"id": "xxxxx",
"action": "Do",
"resource": "Login",
"type": "ok",
"data": {
"username": "+521234567890",
"password": "12345"
}
}"""
val words = listOf("dog","flower","cat")
messageValidator(message,words)}
fun validator(message:String, props:List<String>):Boolean{
val words = props.iterator()
val messagejson = Json.parseJson(message).jsonObject
for(x in words){
//println(x)
//val dataWords = messagejson.containsKey(x)
val dataWords = messagejson.containsKey(x)
//println(dataWords)
if (dataWords == true){
println(x)
return true
}
if (!dataWords){
println(x)
return false
}
}
return false }
我真的不知道如何继续验证