python convert escaped string

巴扎黑
Release: 2016-11-26 10:56:35
Original
1282 people have browsed it

python converts escaped strings

Sometimes we may get the following string:

Python code

>>> a = '{\"name\":\"michael\" }'

>>> print a

{"name":"michael"}

So how to convert it into a dictionary?

You can use the following method:

Python code

>>> type(json.loads('"' + a + '"'))

> ;>> type(json.loads(json.loads('"' + a + '"')))

The first time json.loads is the " Such a string is converted into "(only one double quote), and then converted into a dictionary for the second time. Remember not to forget to add the double quotes in front.


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template