There follows a file, as follows
{ "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", }
By the above-described json module to instantiate a file
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)
But the error, as follows
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)
Baffled, double quotes my file number is used ah
In fact, the root of the problem at the end of the line is the last line of the document, more than a comma, remove the comma on it.
Files modified content
{ "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" }
Read again, the content can be read out of normal
/root/test/test1.template /root/test/test2.template /root/test/test3.template /root/test/test4.template /root/test/test5.template /root/test/test6.template
problem solved! ! !