demjson.encode(self, obj, nest_level=0) :用于将 Python 对象编码成 JSON 字符串。
#!/usr/bin/python import demjsondata = [ { '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 demjsonjson = '{"a":1,"b":2,"c":3,"d":4,"e":5}';text = demjson.decode(json) print text