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
?