Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 列表不可序列化_Python_Json_Serialization - Fatal编程技术网

Python 列表不可序列化

Python 列表不可序列化,python,json,serialization,Python,Json,Serialization,我目前正在使用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,

我目前正在使用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
时间数组、音乐长度和最大值(点)工作正常。时间数组列表:


您有什么想法吗?

您可以打印列表中每个对象的类型,而不是打印列表吗?e、 g.
打印[为x点键入(x)]
?根据JSON库(我认为它使用了
isinstance
检查),可能您得到了一些看起来像int、闻起来像int的对象,但不是
int
。您是对的,我的列表中有一些numpy.int64值!对不起打扰了
res = json.dumps({'map_x' : timeArray, 'map_y' : dots ,'length' : str(music_length), 'max' : str(max(dots))})