2024-06-08_python操作json

2024-06-07  本文已影响0人  微笑碧落

前言

1. json文件转换为python字典

import json
with open('json.file') as f:
  data = json.load(f)

2. json字符串转换为python字典

import json
data = json.loads(json_str)

3. python字典转换为json文件

import json
with open('json.file') as f:
  json.dump(data, f, indent=4)

4. json.dump写入文件后显示\u解决办法

import json
with open('json.file') as f:
  json.dump(data, f, indent=4, ensure_ascii=False)

5. python字典转换为json字符串

import json
with open('json.file') as f:
  json.dumps(data, f, indent=4)
上一篇 下一篇

猜你喜欢

热点阅读