Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the failure of python json.loads

Shulou Source: shulou.com Published: 2022-05-31 10:38:19 09月15日 Update

Most people do not understand the knowledge points of this article "how to solve python json.loads failure", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can gain something after reading this article. Let's take a look at this "how to solve python json.loads failure" article.

Json.loads Python error:

1. 'utf8' codec can't decode byte...

Due to the demand, it is necessary to use python to read the web page and return json, and get the data in it, but encounter the above coding problem.

Finally found a solution:

We just need to unicode the string and ignore the error.

The code is as follows:

Str2 = unicode (str, errors='ignore')

Note, however, that the str here must be a string, and then send it to json.load after processing.

Data = json.loads (str2)

Unicodezation + ignoring errors is awesome.

2. ValueError: Invalid\ escape: line 1 column 35442 (char 35441)

The problem is that there is something like\ xa0 in the code, and the above error occurs when you encounter something like\ http that does not need to be escaped.

Solutions are as follows:

Import re regex = re.compile (r'\\ (?! [/ u ")') fixed = regex.sub (r"\ ", original) the above is about" how to solve the failure of python json.loads ". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Content errors characters strings articles schemes knowledge articles coding solutions problems no code value most that is data more steps knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi vpn Shulou Technology Xiaomi