在
http://blog.csdn.net/5iasp/article/details/23338039
的基础上改进了下
不多说了,直接贴代码:
# _*_coding:utf-8 _*_
import sys
reload(sys)
sys.setdefaultencoding('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(type(data))
print json.dumps(jsonStr).decode('unicode-escape').decode('unicode-escape')
输出结果:
"{"info": {"code": 1, "sex": "男", "id": 1900, "name": "张三"}, "code": 1, "name": "张三", "sex": "男", "data": [{"code": 1, "sex": "男", "id": 1900, "name": "张三"}, {"code": 1, "sex": "男", "id": 1900, "name": "张三"}, {"code": 1, "sex": "男", "id": 1900, "name": "张三"}], "id": 1900}"