python-json

demjson.encode(self, obj, nest_level=0) :用于将 Python 对象编码成 JSON 字符串。

#!/usr/bin/python
import demjson

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

json = demjson.encode(data)
print json

 

demjson.decode(self, txt) :解码 JSON 数据,该函数返回 Python 字段的数据类型。

#!/usr/bin/python
import demjson

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

text = demjson.decode(json)
print  text

 

posted @ 2018-05-13 16:24  benchdog  阅读(126)  评论(0编辑  收藏  举报