[JSON加载函数给出了额外的数据值错误

问题描述 投票:0回答:1

当我读取JSON文件时,它给我以下错误:

json.decoder.JSONDecodeError: Extra data: line 16043 column 2 (char 370886)

此错误似乎是有效的,因为json.load无法解码多个JSON对象,并且我的JSON包含2个或更多对象。

{ "log": [ 
 {
   "code": "info",
   "message": {"text": "[info] Activation of plug-in abcd rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule "},
   "refs": [{"href": "xule"}],
   "level": "info"
 }
,
{
   "code": "xyz.F1.all.7",
   "level": "error",
   "message": {
                "text": "[xyz.F1.all.7] The value for ForResale with a value of 63 has a unit of utr:MWh. This concept allows units of utr:MWh.\n\nElement : xyz:ForResale\nPeriod : 2016-01-01 to 2016-12-31\nUnit : utr:MWh\n\nRule Id:xyz.F1.all.7 - TestUtilitiesInc-428-2016Q4F1.abcd 4114",
                "severity": "error",
                "cid": "63096080",
                "filing_url": "C:\\Users\\TEST\\Desktop\\TestUtilitiesInc-428-2016Q4F1.abcd"
             },
   "refs": [{"href": "xule"}]      

}]
}
{ "log": [ 
 {
   "code": "info",
   "message": {"text": "[info] Activation of plug-in abcd rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule "},
   "refs": [{"href": "xule"}],
   "level": "info"
 }
,
{
   "code": "xyz.F1.all.7",
   "level": "error",
   "message": {
                "text": "[xyz.F1.all.7] The value for ForResale with a value of 63 has a unit of utr:MWh. This concept allows units of utr:MWh.\n\nElement : xyz:ForResale\nPeriod : 2016-01-01 to 2016-12-31\nUnit : utr:MWh\n\nRule Id:xyz.F1.all.7 - TestUtilitiesInc-428-2016Q4F1.abcd 4114",
                "severity": "error",
                "cid": "63096080",
                "filing_url": "C:\\Users\\TEST\\Desktop\\TestUtilitiesInc-428-2016Q4F1.abcd"
             },
   "refs": [{"href": "xule"}]


}]}

我通过这篇文章寻求解决方案:Python json.loads shows ValueError: Extra data这表示我需要在json.dumps()之前在json.loads()中添加我的日志字典。但是,我无法完成它。请任何人能帮助我。

这是我的python代码:

with open('C:/Users/Desktop/SampleTestFiles/logfile.json', encoding="utf-8") as json_file:
    data = json.load(json_file)
python json
1个回答
0
投票

根据jsonlint:

Error: Parse error on line 27:
...le"          }]      }   ]} {    "log": [{           "cod
------------------^
Expecting 'EOF', '}', ',', ']', got '{'

换句话说,您有两个json,应该是一个列表,如

[{
        "log": [{
                "code": "info",
                "message": {
                    "text": "[info] Activation of plug-in abcd rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule "
                },
                "refs": [{
                    "href": "xule"
                }],
                "level": "info"
            },
            {
                "code": "xyz.F1.all.7",
                "level": "error",
                "message": {
                    "text": "[xyz.F1.all.7] The value for ForResale with a value of 63 has a unit of utr:MWh. This concept allows units of utr:MWh.\n\nElement : xyz:ForResale\nPeriod : 2016-01-01 to 2016-12-31\nUnit : utr:MWh\n\nRule Id:xyz.F1.all.7 - TestUtilitiesInc-428-2016Q4F1.abcd 4114",
                    "severity": "error",
                    "cid": "63096080",
                    "filing_url": "C:\\Users\\TEST\\Desktop\\TestUtilitiesInc-428-2016Q4F1.abcd"
                },
                "refs": [{
                    "href": "xule"
                }]

            }
        ]
    },
    {
        "log": [{
                "code": "info",
                "message": {
                    "text": "[info] Activation of plug-in abcd rule processor (xule) successful, version Check version using Tools->Xule->Version on the GUI or --xule-version on the command line. - xule "
                },
                "refs": [{
                    "href": "xule"
                }],
                "level": "info"
            },
            {
                "code": "xyz.F1.all.7",
                "level": "error",
                "message": {
                    "text": "[xyz.F1.all.7] The value for ForResale with a value of 63 has a unit of utr:MWh. This concept allows units of utr:MWh.\n\nElement : xyz:ForResale\nPeriod : 2016-01-01 to 2016-12-31\nUnit : utr:MWh\n\nRule Id:xyz.F1.all.7 - TestUtilitiesInc-428-2016Q4F1.abcd 4114",
                    "severity": "error",
                    "cid": "63096080",
                    "filing_url": "C:\\Users\\TEST\\Desktop\\TestUtilitiesInc-428-2016Q4F1.abcd"
                },
                "refs": [{
                    "href": "xule"
                }]


            }
        ]
    }
]
© www.soinside.com 2019 - 2024. All rights reserved.