python 中json的解析

使用 JSON 函数需要导入 json 库:import json

函数描述
json.dumps 将 Python 对象编码成 JSON 字符串
json.loads 将已编码的 JSON 字符串解码为 Python 对象

import  json

dit={'name':1,"class":"娜美",'age':25}
"""中文转换时设置ensure_ascii=False"""
print(json.dumps(dit,ensure_ascii=False))
json1=json.dumps(dit,ensure_ascii=False)

注意:如果转换的数据中有中文,需要设置ensure_ascii=False 。


dit2=json.loads(json1)
print(dit2)
原文地址:https://www.cnblogs.com/zzzao/p/9176442.html