python - 在python中读取json中的数组
问题描述
我正在尝试在 json 中的数组中读取值(dload 是一个从 url 读取 json 的包,我想访问“用户名”:“Mic123”)
json
{"id": "884087991803124224", "name": "Test's server", "instant_invite": null, "channels": [{"id": "884087923803124228", "name": "General", "position": 0}], "members": [{"id": "0", "username": "Mic123", "discriminator": "0000", "avatar": null, "status": "online", "avatar_url": "https://cdn.discordapp.com/widget-avatars/-WkB9BvIc5Cf98sDorItQJAxQe2zFRSPu2rUMZa329E/ax2jbnjNHRatHiSN0ErxEAFWlGKIAriBh4nOAWpetSDxpYAZRM7a4vGODKipMekSOnHqEdvti4MFVMsYXPnK7gmYU6yowd8FhxSqq5dKIH2a3ouw7eW9uisKiCogMiBpbwOfM4K_GuZX5Q"}], "presence_count": 1}
我试试这段代码
print(dload.json(licencekeyurl['members'][0]["username"]))
输出
TypeError: string indices must be integers
解决方案
for key,value in data.items():
if key == "members":
for key1,value1 in value[0].items():
print(value1)
推荐阅读
- javascript - 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:包子路径 './src/util/Constants.js' 未由 \"exports\" 定义
- rabbitmq - RabbitMQ - 将具有共同属性的消息发送给同一消费者
- swift - SwiftUI - 视频播放器错误
- c++ - 如何激活 Visual Studio 代码中的错误波?
- json - 将遍历树字符串附加到 json-object 以在 python 中检索 json-data
- dataframe - PySpark 仅保留年份和月份
- amazon-web-services - 是否可以创建一个 aws cron 表达式来安排 aws 批处理作业在每个月的第一个、第二个和第三个星期二运行?
- ios - 删除分段控件不需要的背景`multiplied`颜色
- python - 如何在Mac上找到更改IDLE主题的文件夹?
- javascript - 为什么删除它在另一个变量中工作?