Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the failure of python json.loads

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report