python - 类型错误:JSON 对象必须是 str,而不是 Jupyter 笔记本上的“字节”
问题描述
完全相同的代码
A=b'["c1006","c1007"]'
json.loads(A)
在 Python 控制台中工作,但在 Jupyter 笔记本中不起作用,说
TypeError: the JSON object must be str, not 'bytes'
为什么以及如何修复/编写可移植的?
我在 Linux 上使用 Python 3.x:
(py36) dims@calculon:~$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> A= b'["c1006","c1007"]'
>>> json.loads(A)
['c1006', 'c1007']
解决方案
为我工作:
The version of the notebook server is: 5.6.0
The server is running on this version of Python:
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)]
A=b'["c1006","c1007"]'
json.loads(A)
['c1006', 'c1007']
检查您的版本,似乎运行的 python 版本与您的 anaconda 不同:
import sys
sys.version
推荐阅读
- python - 用 for 循环填充字典
- mysql - mysql group by, max, count 实现
- c - 将共享库与 libm 链接
- c++ - 静态链接到 VC++ 运行时,同时包含动态链接到它的静态库
- reactjs - 使用变量反应 Typescript 访问枚举值
- c# - Visual Studio 安装项目:在没有管理员权限的情况下运行 msi 安装程序
- python - 保存嵌套列表理解的结果
- android - 你如何设置一个裸工作流反应原生项目?
- python - 如何并行运行多个开放式 AI 健身房环境
- flutter - 如何访问存储在 Future 中的数据
在 FutureBuilder