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

  • 關於本站
  • 免責聲明