json读取错误json.decoder.JSONDecodeError:无效\ escape

时间:2017-06-21 23:01:29

标签: python json parsing solr

我正在编写一个代码,使用“config.json”文件设置在solr中上传模型(train_and_upload_demo_model.py)。但我得到以下错误:

json.decoder.JSONDecodeError:无效\转义:第11行第34列(字符461) 这是追溯:

D:\solr640\contrib\ltr\example>python train_and_upload_demo_model.py -c config.json

Traceback (most recent call last):
  File "train_and_upload_demo_model.py", line 182, in <module>
    sys.exit(main())
  File "train_and_upload_demo_model.py", line 158, in main
    config = json.load(configFile)
  File "C:\Users\Pankaj\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Users\Pankaj\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Pankaj\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Pankaj\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 11 column 34 (char 461)


content of config.json file

  {
    "host":                     "localhost",
    "port":                     8983,
    "collection":               "techproducts",
    "requestHandler":           "query",
    "q":                        "*:*",
    "efiParams":                "efi.user_query='$USERQUERY'",
    "userQueriesFile":          "user_queries.txt",
    "trainingFile":             "exampleTrainingFile.txt",
    "trainedModelFile":         "exampleTrainedModel.txt",
    "trainingLibraryLocation":  "D:\liblinear-2.11",
    "trainingLibraryOptions":   "-q",
    "solrFeaturesFile":         "exampleFeatures.json",
    "solrFeatureStoreName":     "exampleFeatureStore",
    "solrModelFile":            "exampleModel.json",
    "solrModelName":            "exampleModel"
  }

我可以知道我在哪里弄错了吗?

这是因为“trainingLibraryLocation”:“D:\ liblinear-2.11”,语法错误?因为这是行号。 11

是否有其他方法可以传递目录位置。

1 个答案:

答案 0 :(得分:3)

\l中的"trainingLibraryLocation": "D:\liblinear-2.11"被视为转义序列。尝试逃避斜线本身,即。 "D:\\liblinear-2.11"