有哪些做壁纸的网站好,快速提升网站权重,wordpress加百度一下,服务质量好的外贸营销系统记一个JSON返回数据的bug:‘Object of type int64 is not JSON serializable’ 我在打包数组进行json数据返回时#xff0c;有一个参数是numpy数组里计算出来的#xff0c;类型为int64#xff0c;直接进行json打包会报错 提示(‘Object of type int64 is not JSON serializa…记一个JSON返回数据的bug:‘Object of type int64 is not JSON serializable’ 我在打包数组进行json数据返回时有一个参数是numpy数组里计算出来的类型为int64直接进行json打包会报错 提示(‘Object of type int64 is not JSON serializable’,) 查阅了一些资料这是因为 JSON 标准规定只支持有限的数据类型而 int64 不是其中之一。
然后我又搜了一下python的数据类型int64和int有什么区别int64在 什么情况下会出现得到如下答案 在 Python 中int 是整数的基本数据类型而 int64 是 numpy 库中的数据类型用于表示 64 位整数。
int 是 Python 内置的整数类型它可以表示任意大小的整数。在大多数情况下我们使用的整数都是 int 类型。
而 int64 是 numpy 库中的数据类型用于处理需要精确表示 64 位整数的情况。int64 类型的整数范围更大可以表示更大的整数值而不会溢出。
通常情况下我们不会直接使用 int64 类型除非需要处理大整数或者需要与 numpy 库进行交互时。在一些科学计算和数据分析的场景中numpy 库常常会使用 int64 类型来表示整数数据。
需要注意的是Python 的内置整数类型 int 在大多数情况下可以满足我们的需求而且更常见和易于使用。只有在特定的情况下比如需要处理大整数或者与 numpy 库进行交互时才需要使用 int64 类型。
后来我把那段代码进行格式转化转换成float类型才没有报这个错误了 下面附上代码片段 for dimension in dimension_list:element_df result.loc[result[dimension] dimension].reset_index(dropTrue)dimension_dict {}dimension_dict[dimension] dimensiondimension_dict[JS] element_df[js_sum].loc[0]dimension_dict[EP] element_df[ep_sum].loc[0]dimension_dict[element] element_df[[elements, surprise, EP]].reset_index(dropTrue).to_dict(orientrecords)result_list.append(dimension_dict)json_str[rcode] 0json_str[desc] 定位根因successjson_str[dimension] result_list修改后的 for dimension in dimension_list:element_df result.loc[result[dimension] dimension].reset_index(dropTrue)dimension_dict {}dimension_dict[dimension] dimensiondimension_dict[JS] float(element_df[js_sum].loc[0])dimension_dict[EP] float(element_df[ep_sum].loc[0])dimension_dict[element] element_df[[elements, surprise, EP]].reset_index(dropTrue).to_dict(orientrecords)result_list.append(dimension_dict)json_str[rcode] 0json_str[desc] 定位根因successjson_str[dimension] result_list