代码之家  ›  专栏  ›  技术社区  ›  Dims

typeerror:json对象必须是str,而不是jupyter笔记本上的“bytes”

  •  0
  • Dims  · 技术社区  · 6 年前

    同样的代码

    A=b'["c1006","c1007"]'
    json.loads(A)
    

    在python控制台中工作,但在jupyter笔记本中不工作

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

    为什么以及如何修复/编写可移植的?


    我在Linux上使用Python3.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']
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Arbazz Hussain    6 年前

    对我有用:

    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