pytyon 自带json包,但是直接这样用会报错:
import json
str = "{'jack':12012,'luck':12123}"
json.loads(str)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 1 (char 1)
很恶心的必须要求是str="{\"jack\":\"1232123\"}"
可以使用ast
import ast
result = ast.literal_eval(your_json_string)
http://www.doughellmann.com/PyMOTW/json/