python数据转换:字典和json之间的转换

2021/7/19 20:39:46

本文主要是介绍python数据转换:字典和json之间的转换,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

import json

# dict
bbb = {
    "a": 1,
    "b": "aaa",
    "x": (1, 2, 3),  # tuple 元组
    "c": [1222, 222, True, None, False, {"aaaa": "222"}],
    "d": None,
    "f": True,
    "g": 122.2,
    "h": {
        "aaa": "HELLO",
        "bbb": "122"
    }
}
print(bbb) 
print(type(bbb))  # dict

dict_json = json.dumps(bbb)  # dict转json
print(dict_json)
print(type(dict_json))   # str

json_dict = json.loads(dict_json)  # json转dict
print(json_dict)
print(type(json_dict))  # dict


这篇关于python数据转换:字典和json之间的转换的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程