当我jsonify一个类似于
{'options': {'seriesName': 'Count', 'startYear': 2009, 'title': 'Title', 'startMonth': 9, 'startDay': 1, 'data': [39, 199, 1137, 1156, 1168, 1821, 1936, 214, 236, 260, 282, 305, 323, 344, 3565, 384, 411, 430, 4540, 473, 521, 548, 576, 6222, 6257, 6982, 7216, 2746, 78230, 8126, 85432, 943217, 1024323, 1113, 1155, 142196, 1243, 1271, 1290, 1327, 1365, 1407, 1451, 1537, 1642, 1742, 1811, 1862, 1936, 1978, 2012, 20655, 2093, 2156, 2203, 22289, 24319, 254424, 2614, 2682, 2755, 2811, 2862, 2949, 30262, 31615, 32301, 343309, 343299, 364236, 332721], 'yAxisLabel': 'Count', 'yMinValue': 0}}我最后
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 39 is not JSON serializable据我理解,39应该是可序列化的,对吗?
这似乎在列表中的第一个int上失败了。是否有我不知道的jsonify行为?
发布于 2015-08-26 17:29:16
你没有实际的整数。您可能有一个numpy.float64或类似的对象,它在打印时看起来很像整数。例如,熊猫生产这些数据,见它们的 documentation。
您必须将这些转换为int,或者教JSONEncoder如何显式地处理这些问题。
对于numpy ndarray,将其转换为一个列表,使用 method获取本地 method类型。
https://stackoverflow.com/questions/32231892
复制相似问题