简体   繁体   English

这个 json.load 有什么问题?

[英]What is wrong with this json.load?

I have this code in python 3我在python 3中有这个代码

import json
with open('calldb.json', 'r') as G:
    data = json.load(G)
    print(data)

and this json file和这个json文件

[
   {
     "n": {
       "identity": 0,
       "labels": [
         "Service",
         "Test"
       ],
       "properties": {
         "name": "Service1",
         "uid": "XD2020",
         "state": "new",
         "type": "internetDualhome"
       }
     }
   },
   {
     "n": {
       "identity": 1,
       "labels": [
         "Test",
         "intpe"
       ],
       "properties": {
         "name": "Pe1",
         "ip": "172.20.20.1/32"
--------skipped lines-----------

those omitted lines are for not sharing the entire file那些省略的行是为了不共享整个文件

when i run the program i get this error当我运行程序时出现此错误

raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)引发 JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

what is the problem with this json?这个json有什么问题?

Did you add Skipped lines?您是否添加了跳过的行? If you did not add that line, your file is not formatted to be valid JSON.如果您没有添加该行,则您的文件未格式化为有效的 JSON。

If you added that line, I would recommend checking your JSON file against a JSON schema.如果您添加了该行,我建议您根据 JSON 架构检查您的 JSON 文件。 Its possible you do not have a proper bracket or curl in the right spot.您可能没有合适的支架或在正确的位置卷曲。

I have used this JSON schema validator in the past and find their syntax to be quite helpful.我过去使用过这个JSON 模式验证器,发现它们的语法非常有用。 If you are not sure what version of the schema to select in the drop-down, I recommend defaulting to Draft v4如果您不确定要在下拉列表中选择哪个版本的架构,我建议默认为 Draft v4

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

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