python - python中将字节数据结构转换为字典

标签 python

我收到的 API 响应为 b'[{'key1':'a','key2':'b'},{}....]。我想将它转换为 json 并从函数中返回它。我需要将其转换成什么。请帮忙。

我尝试解码(“utf-8”),但它返回一个字符串。

 result=b'[{'key1':'a','key2':'b'}]'
 f=result.decode("utf-8")

最佳答案

也许是这样的:

import json

json.loads(
    result.decode('utf-8')
)

关于python - python中将字节数据结构转换为字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57190339/

相关文章:

没有方法的Python模块包

Python SQLAlchemy pyodbc.错误: ('HY000' , 'The driver did not supply an error!')

python - 为什么整数除法返回 float ?

python - 如何在 Python (Flask) 应用程序中捕获 psycopg2.errors.UniqueViolation 错误?

python - 如果我打开文件而不分配它,文件是否会保持打开状态?

python - Matplotlib 中具有互连的堆叠二维图

python - 除每个列表的第一个值之外的嵌套列表行的总和

python - py.test 测试 flask 寄存器,AssertionError : Popped wrong request context

python - 如何在 matplotlib 中向轴刻度标签添加路径效果?

python - 正则表达式 : replace comma in string, Python