python中json格式数据输出的简单实现方法
主要使用json模块,直接导入import json即可。
小例子如下:
#coding=UTF-8 import json info={} info["code"]=1 info["id"]=1900 info["name"]='张三' info["sex"]='男' list=[info,info,info] data={} data["code"]=1 data["id"]=1900 data["name"]='张三' data["sex"]='男' data["info"]=info data["data"]=list jsonStr = json.dumps(data) print "jsonStr:",jsonStr
关键代码:jsonStr = json.dumps(data) <span style="font-family:Arial;BACKGROUND-COLOR: #ffffff">执行输出如下:</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"}], "id": 1900}
相关推荐
sifeimeng 2020-06-21
阿斌Elements 2020-05-05
songerxing 2020-05-03
yixiaoqi00 2020-04-22
要啥自行车一把梭 2020-04-17
随心而作 2020-04-07
JayFighting 2020-04-07
80327065 2020-03-09
lhxxhl 2020-03-06
woxmh 2020-03-04
hgzhang 2020-02-18
时光如瑾雨微凉 2020-02-02
winmeanyoung 2020-01-29
wyqwilliam 2020-01-17
typhoonpython 2020-01-12
sofast 2020-01-08
KaiZhaoKZ 2019-12-29