Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 词典中的列表_Python_Loops_Dictionary - Fatal编程技术网

Python 词典中的列表

Python 词典中的列表,python,loops,dictionary,Python,Loops,Dictionary,我似乎无法从API的字典响应中轻松访问列表值 data = { 'room_id': room, 'how_many': 1 } response_url = 'https://api.clickmeeting.com/v1/conferences/'+ str(room) +'/tokens' response1 = requests.post(response_url, headers=headers, data=data). response1.raise_for_s

我似乎无法从API的字典响应中轻松访问列表值

data = {
'room_id': room,
'how_many': 1
 }

 response_url = 'https://api.clickmeeting.com/v1/conferences/'+ str(room) +'/tokens'



 response1 = requests.post(response_url, headers=headers, data=data).  

 response1.raise_for_status()
 # access JSOn content
 jsonResponse = response1.json()

 print(jsonResponse)
答复是:
{'access_tokens':[{'token':'C63GJS','sent_to_email':None','first_use_date':None}}

我希望将标记值分配给一个变量


有什么想法吗?

如果
access\u tokens
中的列表长度始终为1,您可以执行以下操作:

token = json_response["access_token"][0]["token"]
如果
access\u tokens
中可能有多个项目,则类似的情况如下:

tokens = []
access_tokens = json_response["access_token"]
tokens = [at["token"] if "token" in at for at in access_tokens]

access\u-tokens
中的列表是否总是长度为1?
jsonResponse['access\u-tokens'][0]['token']
应该让您打印出来,我建议您一步一个脚印,从
print(jsonResponse['access\u-token'])
开始,然后诸如此类,您遇到了什么问题?当您尝试访问它时是否出现错误?json_响应[['access_token'][0]['token']如果数据不是来自json响应,您将如何处理?