python - 将字节对象列表转换为 dict
问题描述
我正在使用一个 API,它返回 JSON 中的对象列表。但是当我使用 Requests lib 获取它的内容时,内容是一个字节数组的对象,如下所示:
b'[{"id":44,"id_string":"a2BPQDsGLfLiwo4r5U4JCY","title":"ED_1803_ITAIPAVA_RJ","description":"ED_1803_ITAIPAVA_RJ","url":"https://kobocat.docker.kobo.techo.org/api/v1/data/44"},{"id":57,"id_string":"a3pb3ALiGuQAHD6XzdHAip","title":"ED_v2018_1801_Taba\xc3\xa7u-SP","description":"ED_v2018_1801_Taba\xc3\xa7u-SP","url":"https://kobocat.docker.kobo.techo.org/api/v1/data/57"},{"id":68,"id_string":"a4Gz2dSwRuyQCsjBwNhf3D","title":"ECS_1804_SONHO REAL-BA","description":"ECS_1804_SONHO REAL-BA","url":"https://kobocat.docker.kobo.techo.org/api/v1/data/68"},{"id":2,"id_string":"a4KjYoy8ieCRNykiYb7nGP","title":"ECS_1708_Vila Esperan\xc3\xa7a-SP","description":"ECS_1708_Vila Esperan\xc3\xa7a-SP","url":"https://kobocat.docker.kobo.techo.org/api/v1/data/2"},{"id":38,"id_string":"a7GQQ7xEu4K6HXWYu9SaSC","title":"ECo_1711_Terra Nossa-UF","description":"ECo_1711_Terra Nossa-UF","url":"https://kobocat.docker.kobo.techo.org/api/v1/data/38"},{"id":78,"id_string":"a7NnnbdhBUSsGoxVWBiGFb","title":"ECoSP_1805_Vila Nova Esperan\xc3\xa7a-SP","description":"ECoSP_1805_Vila Nova Esperan\xc3\xa7a-SP","url":"https://kobocat.docker.kobo.techo.org/api/v1/data/78"}]
我怎样才能使它成为一个正常的字典列表?我尝试使用 for in range() 遍历字节数组,但我只能返回数字。
解决方案
你可以这样做:
import json
dic = json.loads(Your_input)
推荐阅读
- python-3.x - 如何在不丢失值的情况下重新排序数据框中的列?
- wpf - WPF - 如何为 Itemscontrol 中的特定项目设置 Tab 键顺序
- android - Android:无法使用从 listview 生成的 uri 将文件上传到 firebase
- node.js - 通过 cmd 创建 ember 应用程序时出现以下错误
- google-apps-script - 如何修复 Google Apps 脚本电子邮件查找中的空字段
- react-native - 需要在 Flatlist 中滚动单个项目视图,无论捕捉速度如何
- openam - 如果在 DevOps 模型下重新启动,ForgeRock OpenAM 不会记录消息
- android - 如何在 Android 中添加广播?
- c++ - 如何使用 const char 初始化 string_view 的默认值
- ruby-on-rails - 使用 shopify_api gem 更新智能集合中的产品订单时文件错误结束