簡體   English   中英

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

[英]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)

請注意,我已經互換了fstandardcategories的順序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM