首页 > 编程语言 >python-json

python-json

时间:2022-09-24 10:23:32浏览次数:58  
标签:chinese fw python json file data

python json处理

  1. json写入json文件
点击查看代码
import json
json_data = {
    "name": "Tom",
    "age": 18,
    "score": {
        "math": 98,
        "chinese": 99
    }
}

json_file = 'D:\\2022program\\test.json'
with open(json_file, 'w', encoding='utf-8') as fw:
    json.dump(json_data, fw)
  1. 读取json文件
点击查看代码
json_file = 'D:\\2022program\\test.json'
with open(json_file, 'r', encoding='utf-8') as fw:
    json_data = json.load(fw)
print(json_data)
#{'name': 'Tom', 'age': 18, 'score': {'math': 98, 'chinese': 99}}

标签:chinese,fw,python,json,file,data
From: https://www.cnblogs.com/bonne-chance/p/16725020.html

相关文章