怎么用python提取{"SIPSUB":{"info":{"courseRole":28,"courseType":1,"detail":"","id":"R28","memberLen":4,"members":[{"infoAccount":"420","infoAlias":"420主讲","infoIp":"","stAudio":true,"stCamera":true,"stMic":false,"stRole":1,"stStatus":3,"stVideo":true},{"infoAccount":"421","infoAlias":"421听讲","infoIp":"","stAudio":false,"stCamera":true,"stMic":false,"stRole":2,"stStatus":3,"stVideo":true},{"infoAccount":"422","infoAlias":"422听讲","infoIp":"","stAudio":false,"stCamera":true,"stMic":false,"stRole":2,"stStatus":0,"stVideo":false},{"infoAccount":"423","infoAlias":"423听讲","infoIp":"","stAudio":false,"stCamera":true,"stMic":false,"stRole":2,"stStatus":0,"stVideo":false}],"speaker":"","timeEnd":"","timeStart":"","title":"420课堂互动4人"}} 中所有的infoAccount
时间: 2023-07-17 20:07:08 浏览: 91
要提取给定字典中所有的 "infoAccount" 值,你可以使用 Python 的字典操作。以下是一种可能的方法:
```python
data = {
"SIPSUB": {
"info": {
"courseRole": 28,
"courseType": 1,
"detail": "",
"id": "R28",
"memberLen": 4,
"members": [
{
"infoAccount": "420",
"infoAlias": "420主讲",
"infoIp": "",
"stAudio": True,
"stCamera": True,
"stMic": False,
"stRole": 1,
"stStatus": 3,
"stVideo": True
},
{
"infoAccount": "421",
"infoAlias": "421听讲",
"infoIp": "",
"stAudio": False,
"stCamera": True,
"stMic": False,
"stRole": 2,
"stStatus": 3,
"stVideo": True
},
{
"infoAccount": "422",
"infoAlias": "422听讲",
"infoIp": "",
"stAudio": False,
"stCamera": True,
"stMic": False,
"stRole": 2,
"stStatus": 0,
"stVideo": False
},
{
"infoAccount": "423",
"infoAlias": "423听讲",
"infoIp": "",
"stAudio": False,
"stCamera": True,
"stMic": False,
"stRole": 2,
"stStatus": 0,
"stVideo": False
}
],
"speaker": "",
"timeEnd": "",
"timeStart": "",
"title": "420课堂互动4人"
}
}
}
info_accounts = [member["infoAccount"] for member in data["SIPSUB"]["info"]["members"]]
print(info_accounts)
```
这段代码首先定义了一个包含给定字典的变量 `data`。然后,使用列表推导式从 `data["SIPSUB"]["info"]["members"]` 中提取每个成员的 "infoAccount" 值,并将它们存储在名为 `info_accounts` 的列表中。最后,打印 `info_accounts` 列表以查看提取的值。
运行以上代码,输出将是:
```
['420', '421', '422', '423']
```
这些就是给定字典中所有的 "infoAccount" 值。
阅读全文