TypeError: the JSON object must be str, not ‘bytes’

json.loads(json_ Data) error

Modify to json.loads (JSON_ Data. Decode ()) is OK

Some modifications will bring new error reports

Add code () directly to solve the problem


The python decode() method decodes the string in the encoding format specified by encoding. The default encoding is string encoding


Code() method syntax:



encoding — encoding to be used, such as “UTF-8”

errors — set different error handling schemes. The default is’ strict ‘, which means a Unicode error caused by an encoding error. Other possible values are ‘ignore’, ‘replace’, ‘xmlchar replace’, ‘backslashreplace’ and through codecs. Register_ Any value registered by error()

Return value

This method returns the decoded string


The following example shows an example of the decode() method:

Instance (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’)

The output results of the above examples are as follows:

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE= Decoded String: this is string example....wow!!!

Similar Posts: