Simple implementation of json format data output in python, pythonjson
The json module is used to directly import the import json.
An example is as follows:
# Coding = UTF-8 import json info = {} info ["code"] = 1 info ["id"] = 1900 info ["name"] = 'zhang san' info ["sex "] = 'male' list = [info, info, info] data = {} data ["code"] = 1 data ["id"] = 1900 data ["name"] = 'zhang san' data ["sex"] =' male 'data ["info"] = info data ["data"] = list jsonStr = json. dumps (data) print "jsonStr:", jsonStr
Key code: jsonStr = json. dumps (data) <span style = "font-family: Arial; BACKGROUND-COLOR: # ffffff"> the execution output is as follows: </span> jsonStr: {"info ": {"code": 1, "sex": "\ u7537", "id": 1900, "name": "\ u5f20 \ u4e09"}, "code": 1, "name": "\ u5f20 \ u4e09", "sex": "\ u7537", "data": [{"code": 1, "sex ": "\ u7537", "id": 1900, "name": "\ u5f20 \ u4e09" },{ "code": 1, "sex": "\ u7537 ", "id": 1900, "name": "\ u5f20 \ u4e09" },{ "code": 1, "sex": "\ u7537", "id": 1900, "name": "\ u5f20 \ u4e09"}] and "id": 1900}
The above is all the simple implementation methods for json data output in python provided by xiaobian. I hope you can provide a lot of support ~