我目前正在使用python 2.7,我是初学者。将列表序列化为JSON时遇到问题,我真的不知道问题出在哪里。
我有两个列表:一个是可序列化的,没有任何问题,但第二个引发了错误。为了避免这个问题,我必须将我的列表转换为字符串。
Type dots : <type 'list'>
Values dots : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1703, 6981, 5014, 2655, 4131, 3191, 2610, 2594, 16517, 13536, 21504, 22192, 22117, 20113, 19339, 23008, 20179, 21993, 21515, 22494, 20798, 13912, 17358, 21384, 17588, 20773, 22354, 19671, 17551, 17139, 20675, 20356, 19311, 21079, 16087, 21201, 17444, 21482, 16234, 20242, 19639, 14171, 14556, 20147, 20258, 20193, 18960, 23511, 20557, 15201, 23015, 16535, 21747, 17730, 25433, 14219, 14720, 17947, 16259, 16846, 12736, 19260, 20555, 17180, 15641, 18310, 17630, 15312, 12528, 17529, 18373, 18247, 17745, 18982, 23096, 19991, 22834, 18939, 19900, 16320, 15888, 13644, 21391, 22342, 22126, 15929, 20094, 15577, 21734, 16561, 12705, 20997, 20821, 15267, 15637, 17649, 15416, 21025, 23900, 22196, 21184, 15671, 17843, 19793, 18192, 22604, 21881, 15614, 12492, 14811, 18707, 17404, 17634, 21514, 18781, 14564, 20075, 20242, 18432, 20512, 15914, 17889, 19664, 19168, 15200, 23357, 18413, 12452, 11889, 13214, 12001, 20618, 18079, 15644, 11346, 21598, 14369, 13893, 12600, 18574, 15588, 16560, 20323, 17619, 18756, 19401, 17270, 21888, 15702, 15212, 19269, 16534, 17181, 17945, 22608, 20870, 23538, 14868, 16017, 19467, 16612, 10115, 16634, 16220, 15450, 7374, 14667, 10631, 11355, 11921, 10912, 10821, 10821, 8624, 12527, 11341, 9893, 11130, 11388, 8071, 13293, 14611, 12207, 19194, 14870, 19373, 19517, 17125, 23109, 20609, 15113, 18979, 12370, 15764, 19780, 15087, 17340, 15247, 15812, 21028, 13612, 14042, 15804, 11277, 6825, 5639, 4805, 2304, 351]
Traceback (most recent call last):
File "audioProcess_picsMoyenne.py", line 267, in <module>
res = json.dumps({'map_x' : timeArray, 'map_y' : dots ,'length' : str(duree_musique), 'max' : str(max(dots))})
File "/usr/lib/python2.7/json/__init__.py", line 233, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 203, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 266, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 180, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 1703 is not JSON serializable
这是我的json转储:
res = json.dumps({'map_x' : timeArray, 'map_y' : dots ,'length' : str(music_length), 'max' : str(max(dots))})
timeArray,音乐长度和最大(点)工作正常。 timeArray列表:http://pastebin.com/CuENYH4S
你有什么想法吗?