python - 将列表存储在 json 数据中
问题描述
我想要一个 json 文件,该文件具有tested_versions
存储工具列表及其版本的主键
{
"tested_versions": [{
'version': 1.2,
'tool': 'superb'
}]
}
但是当我尝试使用json.dump(file_obj, json_data)
我收到错误消息
TypeError: <open file '/home/zchang/log/tested_versions.json', mode 'w' at 0x36a09c0> is not JSON serializable
解决方案
也许你必须在 json.dump() 中切换参数的顺序
with open('file.json', 'w') as file_obj:
json.dump(json_data, file_obj)
推荐阅读
- python-3.x - 当有点或逗号时如何在 PEP8 中使用反斜杠?
- pandas - Pandas 数据框转储到 excel 与颜色格式
- android - 有没有办法通过 Android 应用程序中的 StringRequest URL 访问 AWS RDS 数据库?
- mongodb - 使用 MongoDB 时获取组 _id 的数组
- c++ - tensorflow 中 SpatialConvolution 实现的性能
- android - com.rnfs.RNFSManager.mkdir:java.lang.Exception:无法创建目录
- java - 当我已经创建布局时,如何修复“无法解析符号 activity_home”?
- visual-studio - 如何正确链接 MSVC 库
- go - GoLand(JetbBrains)在运行时要求提示不起作用
- android - 由于打开的对话框,应用程序在初始化期间崩溃