有如下一个文件,内容如下

{
"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问题解决的更多相关文章

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

    阐述 想要把一个字符串转化成字典对象,在使用json的过程出现如此报错 解决方法 将字符串里面的单引号改为双引号

  2. python,json解析字符串时ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

    今天写测试工具的时候,去excel取数据,用json解析字符串为字典时报错,后经调试,发现是单引号的原因,将单引号换位双引号即可 def getExcelValue_to_dic(filepath): ...

  3. pandas处理json脱坑(一)--JsonError: Expecting property name enclosed in double quotes

    python执行json.loads(…)时遇到的错误json格式的文本中应该用双引号,而不是单引号,如: brief=json.loads(row["brief"].replac ...

  4. python中报错"json.decoder.JSONDecodeError: Expecting value:"的解决

    在学习python语言中用json库解析网络数据时,我遇到了两个编译错误:json.decoder.JSONDecodeError: Expecting property name enclosed ...

  5. json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    1.json模块常用的四个函数 import json json.load() # 将一个存储在文件中的json对象(str)转化为相对应的python对象 json.loads() # 将一个jso ...

  6. json.loads 报错 json.decoder.JSONDecodeError

    json.loads报json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes 出现这个错误其实只 ...

  7. python Json报错json.decoder.JSONDecodeError

    近期工作中遇到一个问题,执行json.loads(json_data)时,在json_data中加上tab空格后就报错,不加则不报错 一.json.loads(json_data) 报错json.de ...

  8. json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1

    问题描述:使用Python代码将txt城市列表文件转换为xls文件,源码如下, #!/usr/bin/env Python # coding=utf-8 import os import json i ...

  9. python - json模块使用 / 快速入门

    json基本格式 """ json格式 -> [{}, {}]: [{ "name": "Bob", "gende ...

随机推荐

  1. AntDeploy一键发布netcore3.0Windows服务到远程服务器

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...

  2. 【论文阅读】Binary Multi-View Clustering

    文章地址:https://ieeexplore.ieee.org/document/8387526 出自:IEEE Trans. on Pattern Analysis and Machine Int ...

  3. supervisor 安装配置详解

    一.安装 源码安装 先下载最新的supervisor安装包:https://pypi.python.org/pypi/supervisor , 如: (python3命令为 pip install g ...

  4. RESTful API的理解

    技术交流的时候遇到了这样的一个问题,被问及开发中用到的是不是Restful API,我说的是,我们现在用到的不属于完全是Restful API.因为我了解到的Restful API,是 通过具体的UR ...

  5. Tensorflow的基本使用

    基本使用 使用 TensorFlow, 你必须明白 TensorFlow: • 使用图 (graph) 来表示计算任务. • 在被称之为 会话(Session)的上下文 (context) 中执行图. ...

  6. 献给那些想自建站搭建博客的新人们(实篇)wordpress

    实验材料 windows或者linux(因为我是大学操作系统学的是windows,后来服务器转向了linux,所以我将针对window和linux分别进行开展) xampp(最佳php5.6 在7.1 ...

  7. Java并发编程:Callable、Future和FutureTask【转】

    原文链接:http://www.cnblogs.com/dolphin0520/p/3949310.html 创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这 ...

  8. PHP如何获取视频总时长与码率等信息

    利用PHP中的FFmpeg读取视频播放时长与码率等信息   function getVideoInfo($file) {    define('FFMPEG_PATH', '/usr/local/ff ...

  9. 重写系统自带tabbar出现的 代理错误

  10. fsockopen与HTTP 1.1/HTTP 1.0

    在前面的例子中,HTTP请求信息头有些指定了 HTTP 1.1,有些指定了 HTTP/1.0,有些又没有指定,那么他们之间有什么区别呢? 关于HTTP 1.1与HTTP 1.0的一些基本情况,可以参考 ...