如何在嵌套的for循环中解析来自两个不同api调用的json响应?

时间:2019-03-27 21:11:09

标签: python json python-2.7 python-requests

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

我能够从forst 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")

我希望这3个电话都可以提供问题,因为每个电话都是相互依赖的

0 个答案:

没有答案