我正在尝试格式化一些JSON以导入到CouchDB中。单个字符串似乎可以工作,但是我想导入一个相当大的集合(大约700行),JSONLint给出了这个错误
Parse error on line 8:
... "comments": " "}{ "disc_number":
----------------------^
Expecting 'EOF', '}', ',', ']'这是JSON。也许我只是在做傻事,但我看不出有什么问题。
{
"disc_number": "SC2267",
"track_number": "1",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "It's All About the Pentiums",
"artist": "Weird Al Yankovic",
"comments": " "
}{
"disc_number": "SC2267",
"track_number": "2",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "Dare To Be Stupid",
"artist": "Weird Al Yankovic",
"comments": " "
}{
"disc_number": "SC2267",
"track_number": "3",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "One More Minute",
"artist": "Weird Al Yankovic""comments": " ",
}发布于 2015-04-09 05:50:44
您正试图在单个JSON中传递多个断开连接的对象,但JSON仅支持每个文件一个“主”对象。JSONLint在第8行抛出了这个错误,因为它希望文件在对象的末尾完成,但它却继续执行另一个文件。
第一部分本身就是一个有效的JSON:
{
"disc_number": "SC2267",
"track_number": "1",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "It's All About the Pentiums",
"artist": "Weird Al Yankovic",
"comments": " "
}这不是:
{
"disc_number": "SC2267",
"track_number": "1",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "It's All About the Pentiums",
"artist": "Weird Al Yankovic",
"comments": " "
} { "hello": "world!" }另一种解决方案是:
{
"trackX": {
"disc_number": "SC2267",
"track_number": "1",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "It's All About the Pentiums",
"artist": "Weird Al Yankovic",
"comments": " "
},
"trackY": { "etc": "etc" },
"trackZ": { "etcetera": "misc" }
}或者:
{
"tracks": [{ "trackA": "trackAData" }, { "trackB": "trackBData" }]
}对于如何编写有效的json.org文件,JSON有一个简短但完整的描述。这是一个快速阅读;它应该可以帮助您找到一种设置数据格式的好方法。
发布于 2016-09-28 03:06:30
当您的JSON是JSON的集合时,通常会发生这种情况。您必须手动在对象周围添加一个对象包装器,并用",“分隔它们,以使您的文件可解析。
{
"tracks": [{
"disc_number": "SC2267",
"track_number": "1",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "It's All About the Pentiums",
"artist": "Weird Al Yankovic",
"comments": " "
}, {
"disc_number": "SC2267",
"track_number": "2",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "Dare To Be Stupid",
"artist": "Weird Al Yankovic",
"comments": " "
}, {
"disc_number": "SC2267",
"track_number": "3",
"disc_title": "Hits of \"Weird Al Yankovic\" - Vol. 2",
"song_title": "One More Minute",
"artist": "Weird Al Yankovic",
"comments": " "
}]}https://stackoverflow.com/questions/29219744
复制相似问题