首页 > Web开发 > 详细

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

时间:2020-03-16 01:49:55      阅读:127      评论:0      收藏:0      [点我收藏+]
>>> s="{‘name‘:‘Tom‘}"
>>> type(s)
<class str>
>>> json.loads(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\python\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\python\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\python\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

如上,在使用json.loads将str转为dict格式的数据时报错

但如果将s="{‘name‘:‘Tom‘}"改为s=‘{"name":"Tom"}‘,就可以转化成功了

>>> s={"name":"Tom"}
>>> type(s)
<class str>
>>> S=json.loads(s)
>>> S
{name: Tom}
>>> type(S)
<class dict>

看来原因是出现在引号上。。。

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

原文:https://www.cnblogs.com/pfeiliu/p/12501319.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!