简体   繁体   English

TypeError:TextIOWrapper 类型的 Object 不是 JSON 可序列化我不知道如何处理

[英]TypeError: Object of type TextIOWrapper is not JSON serializable I don't know how to handle this

I want to parse this dictionary to a json file.我想将此字典解析为 json 文件。 I saw lots of solutions on google and on this forum but none of them worked.我在谷歌和这个论坛上看到了很多解决方案,但都没有奏效。

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)

Use:利用:

json.dump(standardcategories, f, indent=2)

Instead of:代替:

json.dump(f, standardcategories, indent=2)

Notice that I've interchanged the order of f and standardcategories请注意,我已经互换了fstandardcategories的顺序

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:TextIOWrapper 类型的对象不是 JSON 可序列化的 - TypeError: Object of type TextIOWrapper is not JSON serializable “TypeError”类型的对象不是 JSON 可序列化的 - Object of type 'TypeError' is not JSON serializable TypeError:TypeError 类型的对象不是 JSON 可序列化的 Python - TypeError: Object of type TypeError is not JSON serializable Python TypeError: Object 类型 'type' 不是 JSON 可序列化 - TypeError: Object of type 'type' is not JSON serializable TypeError: Object of type set is not JSON serializable 这是我得到的错误 - TypeError: Object of type set is not JSON serializable This is the error I'm getting 如何处理 TypeError: 'Thread' 类型的对象不是 JSON 可序列化的? - How to deal with TypeError: Object of type 'Thread' is not JSON serializable? 如何处理 TypeError: 'bytes' 类型的对象不是 JSON 可序列化的? - How to deal with TypeError: Object of type 'bytes' is not JSON serializable? 如何克服 TypeError:日期时间类型的 Object 不是 JSON 可序列化的 - How to overcome TypeError: Object of type datetime is not JSON serializable 如何修复“ TypeError:字节类型的对象不可JSON序列化” - How to fix 'TypeError: Object of type bytes is not JSON serializable' 如何修复 TypeError('ExternalUnifiedEvent 类型的对象不是 JSON 可序列化的)? - How to fix TypeError('Object of type ExternalUnifiedEvent is not JSON serializable)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM