TypeError: the JSON object must be str, not 'TextIOWrapper'
来源:互联网 发布:node.js 进入目录 编辑:程序博客网 时间:2024/06/10 06:58
我用的是python3,我的加载代码是:
# 读取数据 with open('dict_author_id.json', 'r') as f: data = json.loads(f) print(data["R. Lauterbach"])
然后报错了,错误信息为:
Traceback (most recent call last): File "data_preprocessing.py", line 111, in <module> process() File "data_preprocessing.py", line 105, in process dp.load_json() File "data_preprocessing.py", line 41, in load_json data = json.loads(f) File "/usr/lib/python3.5/json/__init__.py", line 312, in loads s.__class__.__name__))TypeError: the JSON object must be str, not 'TextIOWrapper'
然后查资料,把data = json.loads(f)换成:
data = json.load(f)就行了.
理由是load是从文件里面load,loads是从str里面load
参考文献
[1].Python - JSON Load from file not working.https://stackoverflow.com/questions/26072148/python-json-load-from-file-not-working
阅读全文
0 0
- TypeError: the JSON object must be str, not 'TextIOWrapper'
- TypeError: the JSON object must be str, not 'bytes'
- TypeError: must be str, not bytes
- TypeError: must be str, not bytes
- 保存网页TypeError: must be str, not bytes
- Python中报错TypeError: must be str, not bytes
- TypeError: write() argument must be str, not bytes
- python-TypeError: write() argument must be str, not numpy.float64
- docx2txt TypeError: write() argument must be str, not bytes
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- TypeError:exceptions must be old-style classes or derived from BaseException, not str
- 处理错误TypeError: initial_value must be unicode or None, not str
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- Python BeautifulSoup [解决方法] TypeError: list indices must be integers or slices, not str
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- python提示错误TypeError: write() argument must be str, not bytes
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+
- 关于TypeError: strptime() argument 1 must be str, not bytes解析
- STM32f429开发中USB读写文件涉及到的库移植
- shell 脚本报错"[: =: unary operator expected"
- 阿里云服务安装与JavaWeb项目配置
- 系统80端口被占用解决办法
- dva各文件名目录的解释
- TypeError: the JSON object must be str, not 'TextIOWrapper'
- Mysql的基本正则表达式
- android7.0+关闭wifi连接CA验证
- android其实很简单 -- roaster 以代码构建代码
- LLVM学习笔记(24)
- Android屏幕适配
- Python基础篇之__len__
- 样本熵的matlab程序
- 新一代的Fetch