python3.x - python processing javascript json
漂亮男人
漂亮男人 2017-05-18 11:01:28
0
2
692

I grabbed a piece of json from the web page. When processing it in python, I encountered the problem of double quotes and single quotes. Is there anyone who has dealt with it? Can you help me?
ValueError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
Official regulations require the use of double quotes to represent characters, so I have to replace all single quotes with double quotes first?
Is there a better way?
Json.dumps() first and then loads() will not work either
Although loads() does not report an error, the processing result cannot be used as a dictionary and is in string form
TypeError: string indices must be integers

漂亮男人
漂亮男人

reply all(2)
过去多啦不再A梦

There are some third-party Json libraries that can solve some compatibility issues, such as the problem of single quotes. It seems that Simplejson can do it.

淡淡烟草味

Problem solved

import json
str = "[ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]"
str = str.replace("'",'"')
dict = json.loads(str)
print(type(sss[0])) // dict
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template