Raspberry Pi Json解析错误

Raspberry Pi Json解析错误,json,python-3.x,raspberry-pi,raspberry-pi3,Json,Python 3.x,Raspberry Pi,Raspberry Pi3,我一直在学习用树莓皮3开发一些东西。很明显,python是普遍使用的,我也将使用它。我在学习使用pyimagesearch博客上的代码时遇到了一些问题 parser= argparse.ArgumentParser() parser.add_argument("-c","--conf",required=True, help="Path to configuration file") warnings.filterwarnings("ignore") conf= json.load(o

我一直在学习用树莓皮3开发一些东西。很明显,python是普遍使用的,我也将使用它。我在学习使用pyimagesearch博客上的代码时遇到了一些问题

parser= argparse.ArgumentParser()

parser.add_argument("-c","--conf",required=True, help="Path to configuration file")



warnings.filterwarnings("ignore")

conf= json.load(open(args["conf"]))
我有错误

Traceback (most recent call last):
  File "surveillance_system.py", line 29, in <module>
    conf= json.load(open(args["conf"]))
NameError: name 'args' is not defined
现在,这些错误

Traceback (most recent call last):
  File "surveillance_system.py", line 29, in <module>
    conf= json.load(open(args["conf"]))
  File "/usr/lib/python2.7/json/__init__.py", line 290, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 14 column 2 (char 264)
回溯(最近一次呼叫最后一次):
文件“监视系统.py”,第29行,在
conf=json.load(打开(args[“conf”]))
文件“/usr/lib/python2.7/json/_init__.py”,第290行,装入
**千瓦)
文件“/usr/lib/python2.7/json/_init__.py”,第338行,加载
返回\u默认\u解码器。解码
文件“/usr/lib/python2.7/json/decoder.py”,第366行,在decode中
obj,end=self.raw\u decode(s,idx=\u w(s,0.end())
原始解码中的文件“/usr/lib/python2.7/json/decoder.py”,第382行
obj,end=self.scan_一次(s,idx)
ValueError:应为,分隔符:第14行第2列(字符264)

所以我需要一些帮助。顺便说一句,我是python新手。谢谢。

就我个人而言,我对argparse一无所知,所以我建议您使用getopt。放

import sys

如果您还没有这些代码,那么您的其余代码将如下所示:

try:
   opts, args = getopt.getopt(sys.argv[1:],"c:",["conf="])
except getopt.GetoptError:
   print("Getopt error")
   sys.exit(1)
for opt, arg in opts:
    if opt in ("-c","--conf"):
        conf = json.load(open(arg))

希望这能完成我个人的工作,我对argparse一无所知,所以我建议您使用getopt。放

import sys

如果您还没有这些代码,那么您的其余代码将如下所示:

try:
   opts, args = getopt.getopt(sys.argv[1:],"c:",["conf="])
except getopt.GetoptError:
   print("Getopt error")
   sys.exit(1)
for opt, arg in opts:
    if opt in ("-c","--conf"):
        conf = json.load(open(arg))

希望这能起作用

我的回答对你的问题有帮助吗?如果是的话,你能把我的答案标记为接受吗?我的答案对你的问题有帮助吗?如果是的话,你能把我的回答标记为接受吗?嗨,阿德里安,对不起。我忘了发邮件了。实际上,问题出在json中。我忘了在一个关键字后面加逗号(,)。无论如何,谢谢你的帮助。嗨,阿德里安,对不起。我忘了发邮件了。实际上,问题出在json中。我忘了在一个关键字后面加逗号(,)。无论如何,谢谢你的帮助。