[python] 转json好用的工具mark

demjson

from: https://blog.csdn.net/u011416077/article/details/49407047

使用demjson
encode
#!/usr/bin/python
import demjson

data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]

json = demjson.encode(data)
print json

运行输出
[{"a":1,"b":2,"c":3,"d":4,"e":5}]


decode
#!/usr/bin/python
import demjson

json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

text = demjson.decode(json)
print text

运行输出
{u'a': 1, u'c': 3, u'b': 2, u'e': 5, u'd': 4}


————————————————
版权声明:本文为CSDN博主「Gemini_Dong」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011416077/article/details/49407047

posted @ 2019-10-17 10:13  凌波微步_Arborday  阅读(269)  评论(0编辑  收藏  举报