我想将此列表转置为 groovy 脚本。有两个列表
result_name = ["API(示例)","管理门户(示例)","Component1","Component2",]
result_ids = ["3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]
我期待类似 list[0][0], list[1][1].... 的输出。例如:
API (example) 3wrhs4vp3sp5
Management Portal g2828br1gzw9
Component1 68pnwhltxcq0
Component2 fy8g2nvvdg15
我正在尝试使用
def 结果 = [[result_name], [result_ids]].transpose()
但结果是:
结果:[[["API (example)","Management Portal (example)","Component1","Component2",], ["3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]]]
编辑:更新了问题中的示例代码:
proc1 = ['/bin/bash', '-c', "curl https://api.statuspage.io/v1/pages/lbh0g6b5mwnf/components?api_key=<key>"].execute()
proc2 = ['/bin/bash', '-c', "grep -Po '\"name\": *\\K\"[^\"]*\"'| tr '\n' ', '"].execute()
proc3 = ['/bin/bash', '-c', "curl https://api.statuspage.io/v1/pages/lbh0g6b5mwnf/components?api_key=<key>"].execute()
proc4 = ['/bin/bash', '-c', "grep -Po '\"id\": *\\K\"[^\"]*\"'| tr '\n' ', '"].execute()
all_name = proc1 | proc2
all_ids = proc3 | proc4
def result_name = [all_name.text]
def result_ids = [all_ids.text]
println result_name
println result_ids
def result = [result_name, result_ids].transpose()
结果
["API (example)","Management Portal (example)","Component1","Component2",]
["3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]
Result: [["API (example)","Management Portal (example)","Component1","Component2",, "3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]]