Home  >  Article  >  Backend Development  >  python convert escaped string

python convert escaped string

巴扎黑
巴扎黑Original
2016-11-26 10:56:351244browse

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.


Statement:
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