简体   繁体   English

在Python中读取JSON格式文件

[英]Reading JSON Format File in Python

I'm trying to open a file to view the data in test.json file. 我正在尝试打开一个文件来查看test.json文件中的数据。 File contains string data. 文件包含字符串数据。

Here is my code: 这是我的代码:

import json
from pprint import pprint
    with open("D:\python\abc.json") as json_file:
     json_data = json.load(json_file)
        pprint(json_data)

Here is the error generating, I'm confused as I'm newbie in Python. 这是错误生成,我很困惑,因为我是Python的新手。 Help Required. 需要帮助。

    Traceback (most recent call last):
  File "C:\Users\joh\workspace\newdic\dic.py", line 20, in <module>
    json_data = json.load(json_file)
  File "C:\Python33\lib\json\__init__.py", line 271, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Python33\lib\json\__init__.py", line 316, in loads
    return _default_decoder.decode(s)
  File "C:\Python33\lib\json\decoder.py", line 351, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python33\lib\json\decoder.py", line 367, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 21 column 9 (char 387)

The error is clear. 错误很明显。 ValueError: Expecting ',' delimiter: line 21 column 9 (char 387)

Make sure that the Json file is valid. 确保Json文件有效。

Use http://jsonlint.com/ to validate your Json. 使用http://jsonlint.com/验证您的Json。 Just copy and paste and it will tell you if it is not valid. 只需复制并粘贴即可告诉您它是否无效。 Once it is this library should read it. 一旦它是这个库应该阅读它。 You can post your Json and we can look at it. 您可以发布您的Json,我们可以查看它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM