擅长:python、mysql、java
<p>我重写了你们的代码,改变了字典的数据类型,看到了同样的错误</p>
<pre><code>import json
import numpy as np
thisdict = {'12': [[1, 970000009], [3, 990000547], [9, 900000007]],
'3': [[2, 970022209], [3, 990000547]],
'32': [[4, 94042209], [5, 40547]],
'6575': [[3, 94334009], [2, 923200547], [6, 7807], [7, 98807], [8, 8887]]}
data = list(thisdict.items())
arr = np.array(data)
with open('result.json', 'w') as fp:
json.dump(arr, fp)
</code></pre>
<p>TypeError:类型为<strong>ndarray</strong>的对象不可JSON序列化</p>
<p>我知道你的字典可能有一个Int64数据类型。请检查此目录的类型</p>
<p><strong>解决方案:</strong></p>
<pre><code>import json
import pandas as pd
import numpy as np
thisdict = {'12': [[1, 970000009], [3, 990000547], [9, 900000007]],
'3': [[2, 970022209], [3, 990000547]],
'32': [[4, 94042209], [5, 40547]],
'6575': [[3, 94334009], [2, 923200547], [6, 7807], [7, 98807], [8, 8887]],
}
data = list(thisdict.items())
arr = np.array(data)
df = pd.DataFrame(arr)
df.to_json('result.json')
</code></pre>