代码示例:(标识:python_json_from_python)
python_json_from_python.py
import json

# a Python object (dict):
x = {
  "name": "Bill",
  "age": 63,
  "city": "Seatle"
}

# convert into JSON:
y = json.dumps(x)

# the result is a JSON string:
print(y)
运行结果: