我有一些JSON文件,其内容如下:
{
"name": "",
"street": "",
"street_number": 26,
"district": "VILA MARESIA",
"city": "Raposa",
"state": "",
"country": "BR",
"latitude": ,
"longitude":
}
现在,加载此文件将引发错误,如下所示:
with open(r"C:\Users\dverma25\menus-folder\menus-folder-MA\rt.json",'r', encoding="utf8") as json_file:
json_data = json.load(json_file)
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-93-8150dd6a3e1d> in <module>
2 logger.info("Start processing the file {}".format(file))
3 # t = json_file.read()
----> 4 json_data = json.load(json_file)
C:\ProgramData\Anaconda3\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
294 cls=cls, object_hook=object_hook,
295 parse_float=parse_float, parse_int=parse_int,
--> 296 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
297
298
C:\ProgramData\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
C:\ProgramData\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
C:\ProgramData\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 9 column 15 (char 153)
这背后的原因是“纬度”字段缺少值,该字段既不是空字符串,也不是空字符串(因为源API中的数据类型是这个字段的双倍)。有人能建议一种方法来打开这个文件并在json maodule中加载它吗。
PS:我也尝试打开文件,并使用josn.dump(file_obj.read()),但问题是它也接受了dump()中的所有回车。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。