我正在尝试将字符串(mailId)与响应数据数组进行比较,并获取相应的Id以传递给下一个请求。响应:
[ {
"id": 93,
"sender": "<[email protected]>",
"recipients": [
"<[email protected]>"
],
"subject": "Update Your Account",
"size": "49351",
"created_at": "2023-12-27T08:47:40+00:00"
}, { “ID”:94, "sender": "[电子邮件受保护]", “收件人”:[ “[电子邮件受保护]” ], "subject": "更新您的帐户", “大小”:“49351”, “创建时间”:“2023-12-27T08:49:34+00:00” } ]
我的代码片段是
* def getvalidId =
"""
function(response){
for(var i=0;i<response.length;i++){
if (response[i].subject === "Update Your Account"){
if((response[i].recipients).indexOf(3,25) === "[email protected]")
{
return response[i].id
}
}
}
与 match 、 substring 、 indexof 相关的 Java 脚本函数工作正常,并且仅在空手道中出现问题。请帮助我。
这 3 行足以满足您的用例:
* def fun = x => x.subject == 'Update Your Account' && x.recipients[0] == '[email protected]'
* def found = response.find(fun)
* def id = found.id
要了解其工作原理(如果需要),请参阅:https://stackoverflow.com/a/76091034/143475