我正在尝试格式化一些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": " ",
}
答案 0 :(得分:3)
您尝试在单个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文件。这是一个快速阅读;它可以帮助您找到格式化数据的好方法。
答案 1 :(得分:0)
当您的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": " "
}]}