首页 / JSON / python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决
python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1776字,纯文字阅读大概需要3分钟。
内容图文
![python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决](/upload/InfoBanner/zyjiaocheng/650/1a0dea8ced304df1a7e3d98f565fa3ec.jpg)
有如下一个文件,内容如下
{ "test1": "/root/test/test1.template", "test2": "/root/test/test2.template", "test3": "/root/test/test3.template", "test4": "/root/test/test4.template", "test5": "/root/test/test5.template", "test6": "/root/test/test6.template", }
通过json模块去实例化上述的文件
import json import os import shelve p = os.path.join(os.path.dirname(os.path.abspath(__file__)),"templatepath") file = json.load(open(p,"r")) for k,v in file.items(): print(v)
但是报错,内容如下
Traceback (most recent call last): File "D:/python/test_sip/test_check_es.py", line 323, in <module> file = json.load(open(p,"r")) File "C:\Program Files\Python36\lib\json\__init__.py", line 299, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "C:\Program Files\Python36\lib\json\__init__.py", line 354, in loads return _default_decoder.decode(s) File "C:\Program Files\Python36\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Program Files\Python36\lib\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 8 column 1 (char 254)
百思不得其解,我的文件中都是用的双引号号啊
其实问题的根源是在文件的最后一行的行尾,多了一个逗号,去掉这个逗号就可以了。
修改后的文件内容
{ "test1": "/root/test/test1.template", "test2": "/root/test/test2.template", "test3": "/root/test/test3.template", "test4": "/root/test/test4.template", "test5": "/root/test/test5.template", "test6": "/root/test/test6.template" }
再次读取,内容就可以被正常读取出来
/root/test/test1.template /root/test/test2.template /root/test/test3.template /root/test/test4.template /root/test/test5.template /root/test/test6.template
问题解决!!!
内容总结
以上是互联网集市为您收集整理的python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决全部内容,希望文章能够帮你解决python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。