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

 

 

 

 

 

json.loads(json_data)报错python

修改成json.loads(json_data.decode())便可json

一些修改成load什么的方法会带来新的报错…this

直接添加decode()解决编码

 

 

 

描述

Python decode() 方法以 encoding 指定的编码格式解码字符串。默认编码为字符串编码。spa

语法

decode()方法语法:code

str.decode(encoding='UTF-8',errors='strict')

参数

  • encoding -- 要使用的编码,如"UTF-8"。xml

  • errors -- 设置不一样错误的处理方案。默认为 'strict',意为编码错误引发一个UnicodeError。 其余可能得值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及经过 codecs.register_error() 注册的任何值。blog

返回值

该方法返回解码后的字符串。字符串

实例

如下实例展现了decode()方法的实例:string

实例(Python 3.0+)

#!/usr/bin/python str = "this is string example....wow!!!"; str = str.encode('base64','strict'); print "Encoded String: " + str; print "Decoded String: " + str.decode('base64','strict')

以上实例输出结果以下:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE= Decoded String: this is string example....wow!!!
相关文章
相关标签/搜索