如何從 Python 函式中返回一個 json 物件?


我們使用給定的 Python 字典,透過以下方式從 Python 函式返回一個 json 物件。

示例

import json
a = {'name':'Sarah', 'age': 24, 'isEmployed': True }
# a python dictionary
def retjson():
python2json = json.dumps(a)
print python2json
retjson()

輸出

{"age": 24, "isEmployed": true, "name": "Sarah"}

更新於: 13-2-2020

2K+ 瀏覽量

開啟您的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.