python for loop:
actions = json_data['actions']
for a in actions:
if 'causes' in a:
for cause in a['causes']:
if 'userId' in cause:
self.user = cause['userId']
我如何在groovy中这样做?
def jenkins_data = new JsonSlurper().parseText(obj)
使用这个json,我不知道如何向下钻取以获取userId。我想我需要使用for循环检查列表中每个元素的'cause'键,然后重复'userId'键。
这是我正在处理的示例有效负载。
self.payload_a = {"number": 3585, "url": "https://test.m.test.com/job/gfdsgdsf/3585/",
"displayName": "master_3585", "timestamp": 1516992464686,
"actions": [{"something": "nothing"}, {"causes": [{"userId": "build"}]}]}
使用示例有效负载我能够回显jenkins_data.actions.causes并查看输出 但是回显jenkins_data.actions.causes.userId为null(即使userId肯定在有效负载中)
当我跑步时
echo jenkins_data.actions.causes
我得到了
[null, [[_TestIdCause, shortDescription:Started by user, B, userId:valueweneed, userName:test, B]], null, null, null, null, null, null, null, null, null, null, null, null, null, null]