>>> s = "[1,2,3,4,5,6,7]"
>>> import json
>>> json.loads(s)
[1, 2, 3, 4, 5, 6, 7]
>>> import json
>>> s = '{"a":"b","x":3}'
>>> json.loads(s)
{'a': 'b', 'x': 3}
注意在转化字典的时候字典的里面必需都是双引号,否则报错如
>>> s = '{"a":"b",\'x\':3}'
>>> import json
>>> json.loads(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 10 (char 9)
网友评论