JSON 无效字符 '}' 寻找对象键字符串的开头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29690789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:51:18  来源:igfitidea点击:

JSON invalid character '}' looking for beginning of object key string

jsonparse-platformsyntax-error

提问by blaizor

I am attempting to import a .jsonfile to parse.com, and I have encountered many errors while doing so. I solved them sequentially, but after I click finish import, I get the error

我正在尝试将.json文件导入到parse.com,但在执行此操作时遇到了许多错误。我按顺序解决了它们,但是单击后finish import,出现错误

invalid character '}' looking for beginning of object key string

My JSONscript is, as far as I know, perfectly fine. But I only started using JSONtwo hours ago, so I'm sure there's something wrong with it.

JSON据我所知,我的脚本非常好。但是我JSON两个小时前才开始使用,所以我确定它有问题。

{
  "results": [{
    "nameChunk1": [{
      "name1": "Sean",
      "name2": "Noah",
    }]
    "nameChunk2": [{
      "name1": "Joseph",
      "name2": "Sam",
    }]
  }]
}

So, where is the mysterious invalid }? I fear there are many... Keep in mind I am using JSONfor importing data into parse.com

那么,神秘的无效在哪里}?我担心有很多...请记住我JSON用于将数据导入parse.com

回答by Sandeep Nayak

Correct your JSON syntax:

更正您的 JSON 语法:

{
  "results": [{
     "nameChunk1": [{
        "name1": "Sean",
        "name2": "Noah" 
     }],
     "nameChunk2": [{
       "name1": "Joseph",
       "name2": "Sam"
     }]
  }]
}

Observe that I have added ,after each array.. and removed ,after name2key.

观察我,在每个数组之后添加..并,name2键后删除。

Always use validators such as http://jsonlint.com/to validate your JSON.

始终使用http://jsonlint.com/ 等验证器来验证您的 JSON。

回答by Sach141

Use any JSON validator like http://jsonlint.com/to validate your JSON.

使用任何 JSON 验证器(如http://jsonlint.com/)来验证您的 JSON。

Correct JSON is:

正确的 JSON 是:

{
  "results": [{
     "nameChunk1": [{
        "name1": "Sean",
        "name2": "Noah" 
     }],
     "nameChunk2": [{
       "name1": "Joseph",
       "name2": "Sam"
     }]
  }]
}

回答by Justin Ober

You need to remove the comma's after name2and then insert a comma between nameChunk1and nameChunk2. Valid JSON below:

您需要删除之后的逗号name2,然后在nameChunk1和之间插入逗号nameChunk2。下面是有效的 JSON:

{
  "results": [{
    "nameChunk1": [{
      "name1": "Sean",
      "name2": "Noah"
    }],
    "nameChunk2": [{
      "name1": "Joseph",
      "name2": "Sam"
    }]
  }]
}

回答by Mohsin Ali

There are two issues with the JSON:

JSON 有两个问题:

  1. There should be no ',' after last element of an object
  2. There should be a comma to separate two elements
  1. 在对象的最后一个元素之后不应该有“,”
  2. 应该有一个逗号来分隔两个元素

Below is the valid JSON:

以下是有效的 JSON:

{
  "results": [{
    "nameChunk1": [{
      "name1": "Sean",
      "name2": "Noah"
    }],
    "nameChunk2": [{
      "name1": "Joseph",
      "name2": "Sam"
    }]
  }]
}