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

猜你喜欢

转载自www.cnblogs.com/benchdog/p/9032551.html