我的 JSON 响应的一部分如下所示:
"resources": [{
"password": "",
"metadata": {
"updated_at": "20190806172149Z",
"guid": "e1be511a-eb8e-1038-9547-0fff94eeae4b",
"created_at": "20190405013547Z",
"url": ""
},
"iam": false,
"email": "<some mail id>",
"authentication": {
"method": "internal",
"policy_id": "Default"
}
}, {
"password": "",
"metadata": {
"updated_at": "20190416192020Z",
"guid": "6b47118c-f4c8-1038-8d93-ed6d7155964a",
"created_at": "20190416192020Z",
"url": ""
},
"iam": true,
"email": "<some mail id>",
"authentication": {
"method": "internal",
"policy_id": null
}
},
...
]
我正在使用 Play 框架提供的 Json 助手来解析这个 Json,如下所示:
val resources: JsArray = response("resources").as[JsArray]
现在我需要从JsArrayemail
中的所有这些对象中提取字段。resources
为此,我尝试编写一个 foreach 循环,例如:
for (resource <- resources) {
}
但我Cannot resolve symbol foreach
在<-
标志处遇到错误。如何email
从每个 JSON 对象中检索特定字段JsArray