如何從 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"}
廣告