我如何将填充字符串的数组转换为JSON
n=int(input('n='))
array = np.empty(shape=
[n,4],dtype='|S10')
.
.
.
.
array= array.tolist()
array =[[b'1',b'1/1/1',b'1',b'1']]
dump(array,json_file)
我有一个错误:类型字节的对象不是JSON序列化
n=int(input('n='))
array = np.empty(shape=
[n,4],dtype='|S10')
.
.
.
.
array= array.tolist()
array =[[b'1',b'1/1/1',b'1',b'1']]
dump(array,json_file)
I got an error: Object of type bytes is not JSON serializable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么在字符串之前键入“ B”?
您的代码尚未完成,我对其进行了修改以使其工作:
如果您要当前的代码工作,如果要序列化数量的字符串,则必须使用'u1'dtype,然后将其转换为列表,例如:
Why you type 'b' before the strings ?
Your code is not complete, I modified it to let it work:
That if you want your current code to work, if you want to serialize a numpy array of strings you must use 'U1' dtype and then convert it to list, like this: