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

Description

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

Grammar

Code() method syntax:

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

Parameters

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

Examples

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: