json.dumps 将 Python 对象编码成 JSON 字符串 json.loads 将已编码的 JSON 字符串解码为 Python 对象 import json import pytest #将string转换成dict #见到 : 和 , 就自动转换成dict def test_loads(): s = '{"k1": "v1"}' # 注意:由于是字符串,所以有'' loads_sth = json.loads(s) assert type(loads_sth) == dict