def decodeData(data, d = None): dct = json.loads(data) if not d: d = PBData() d.entries = dct['entries'] [d.data.append(x) for x in dct['data']] [d.variance.append(x) for x in dct['variance']] return d
d.entries = dct['entries'] [d.data.append(x) for x in dct['data']] [d.variance.append(x) for x in dct['variance']] return d if "__main__" == __name__: print "[test] Create PB data, encode to json, decode from json into copy\n" data = PBData() # Underflow # data.data.append(0) data.variance.append(0) data.entries = 25 for i in xrange(1, 10): data.data.append(i * 2) data.variance.append(i * 3) # Overflow # data.data.append(0) data.variance.append(0) print "[data]" print data json_text = encodeData(data)