在用python调用emqx的API时遇到数据格式转换问题

获取的response的格式是bytes的数据类型,我需要转化成字符串或者字典使用,这里复习一下下面几个函数

1. json->string

str = json.dumps(json_type)

2. bytes->string

str = str(bytes_type, 'utf-8')

3. string/json->dict

dict = loads(str)

4. dict->json

json = dumps(dict)

5. 读取json文件->dict

dict = load(json)

6. dict->写入json文件

with open('test.json', 'w') as f:
    json.dump(dict, f)
posted @ 2023-02-21 18:31  三眠  阅读(94)  评论(0)    收藏  举报