我有以下事件体(字典)进入lambda函数,我做了下面的事情:
{
"test-report": {
"url": "http://example.com",
"original-policy": "default-src 'none'; style-src example.com; report-uri /_/test-reports"
}
}
if 'test-report' in event['body']:
try:
do something here
我的问题是我想在字典中的第一个对象中检查test-report
。如果不匹配,我不希望函数做任何事情。但是,正如您所看到的,**test-report**s
也存在于original-policy
值下,我不想在我的if语句中考虑这一点。
好吧,假设您所说的第一个对象是指字典中的键,因为它们是无序的。如果是,请尝试:
if 'test-report' in event['body'].keys():
try:
do something here