![](/img/trans.png)
[英]TypeError: Object of type TextIOWrapper is not JSON serializable
[英]TypeError: Object of type TextIOWrapper is not JSON serializable I don't know how to handle this
我想将此字典解析为 json 文件。 我在谷歌和这个论坛上看到了很多解决方案,但都没有奏效。
import json
standardcategories = {
"unnecessary": 0,
"unimportant": 1,
"important": 2,
"crucial": 3,
"fixed": 4
}
with open('categories.json','w') as f:
json.dump(f,standardcategories,indent=2)
利用:
json.dump(standardcategories, f, indent=2)
代替:
json.dump(f, standardcategories, indent=2)
请注意,我已经互换了f
和standardcategories
的顺序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.