Python 3: Is not JSON serializable

后端 未结 2 2040
日久生厌
日久生厌 2020-12-14 07:03
TypeError: b\'Pizza is a flatbread generally topped with tomato sauce and cheese and baked in an oven. It is commonly topped with a selection of meats, vegetables an         


        
相关标签:
2条回答
  • 2020-12-14 07:50

    This is not a string, but a byte sequence. JSON knows only how to handle Unicode strings, not byte sequences. Either transform into Unicode (json.dumps(x.decode("utf-8"))), or into an integer array (json.dumps(list(x))).

    0 讨论(0)
  • 2020-12-14 07:50

    Consider installing and using simplejson, which can handle bytes strings in addition to unicode, to install it use command below:

    pip3 install simplejson
    

    Usage in code:

    import simplejson as json
    
    json.dumps({b'name': b'dev'})
    
    0 讨论(0)
提交回复
热议问题