我们使用给定的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"}