logo
  • 教程列表
  • SO官方文档
  • JSON 模块
    • 将数据存储在文件中
    • 从文件中检索数据
    • 格式化 JSON 输出
    • 从 Python dict 创建 JSON
    • 从 JSON 创建 Python dict
    • load vs loads dump vs dumps
    • 从命令行调用 json.tool 到漂亮的 JSON 输出
    • JSON 编码自定义对象
  1. StackOverflow 文档
  2. Python Language 教程
  3. JSON 模块
  4. 从 Python dict 创建 JSON

从 Python dict 创建 JSON

Created: November-22, 2018

import json
d = {
    'foo': 'bar',
    'alice': 1,
    'wonderland': [1, 2, 3]
}
json.dumps(d)

以上代码段将返回以下内容:

'{"wonderland": [1, 2, 3], "foo": "bar", "alice": 1}'
  • 从 JSON 创建 Python dict
  • 格式化 JSON 输出

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明