如何从两个不同的api调用解析响应json,但是在嵌套的for循环中具有相同的字典名称和不同的值

时间:2019-03-27 23:07:40

标签: python python-3.x python-2.7 jython jython-2.7

我想从两个不同的api调用解析响应json,但是在嵌套的for循环中具有相同的字典名称和不同的值

我能够从第一个api调用中获取信息,但在第二个api调用中却失败了,并且与两个调用中的问题相同,但键值不同。

def classtest(self):
    apione = "http://jira.com/rest/1"
    headers = {
        'content-type': "application/json",
              } 
    requestglobal = requests.request("GET", apione, headers=headers)
    responseglobal = requestglobal.text
    responseglobal = json.loads(responseglobal)
    for i in responseglobal['issues']:
         issue1 = i[key]
         print(issue1)
         apitwo = "https://jira.com/rest/2" + str(issue1)
         requesttwo = requests.request("GET", apitwo, headers=headers)
         responsetwo = requesttwo.text
         responsetwo = json.loads(responsetwo)
         for i in responsetwo['issues']:
               issue2 = i[key] + str(issue1)
               print(issue2)
               apitthree = "https://jira.com/rest/3" + str(issue1) + str(issue3)
               requestthree = requests.request("GET", apitthree, headers=headers)
               responsethree = requestthree.text
               responsethree = json.loads(responsetthree)
               for i in responsethree['issues']:
                     issue3 = i[key] + str(issue2) 
                     print(issue3)
               print("something from thirdloop")
         print("something from second loop") 
    print ("something from first for loop")

我希望所有三个api调用都能解决所有问题。

0 个答案:

没有答案