TypeError:JSON对象必须是str,而不是Jupyter笔记本上的bytes

2024-10-01 15:37:21 发布

您现在位置:Python中文网/ 问答频道 /正文

完全相同的代码

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']

Tags: the代码jsonobjectnot笔记本jupyterbe
1条回答
网友
1楼 · 发布于 2024-10-01 15:37:21

为我工作:

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

相关问题 更多 >

    热门问题