原文:python中讀取json文件報錯,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’

利用python中的json讀取json文件時,因為錯誤使用了相應的方法導致報錯:TypeError:the Json object must be str, bytes or bytearray,not TextIOWrapper 。 解決方法: 首先要弄明白json有四個方法:dumps和loads dump和load。其中,dumps和loads是在內存中轉換 python對象和json字符 ...

2019-03-03 17:27 0 5053 推薦指數:

查看詳情

TypeError: the JSON object must be str, not 'bytes'

json.loads(json_data)報錯 修改為json.loads(json_data.decode())即可 一些修改為load什么的方法會帶來新的報錯… 直接添加decode()解決 描述 Python decode() 方法 ...

Fri Dec 06 01:00:00 CST 2019 0 484
TypeError: must be str, not bytes

先說下python的版本吧 3.6 1.TypeError: must be str, not bytes錯誤: 解答: 寫文件處 open(filename, 'w').write 應該寫為 open(filename, 'wb').write 2.當文本文件里面有中文時,需要進行編碼轉換 ...

Wed Feb 03 03:56:00 CST 2021 0 666
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM