2017-08-11 334 views
0

在我的IntelliJ编辑器中,我有一个如下的test.json文件。第二个json记录显示错误消息“Json标准只允许一个顶级值”。但是这是一个有效的JSON文件,对吧?如何摆脱这个烦人的消息?“JSON标准只允许一个顶级值”是什么?

{"reviewerID": "A2XVJBSRI3SWDI", "asin": "0000031887", "reviewerName": "abigail", "helpful": [0, 0], "title": "Ballet Dress-Up Fairy Tutu", "url": "http://rads.stackoverflow.com/amzn/click/0000031887", "brand": "Boutique Cutie", "reviewText": "Perfect red tutu for the price. I baught it as part of my daughters Halloween costume and it looked great on her.", "overall": 5.0, "summary": "Nice tutu", "unixReviewTime": 1383523200, "reviewTime": "11 4, 2013"} 
{"reviewerID": "A2G0LNLN79Q6HR", "asin": "0000031887", "reviewerName": "aj_18 \"Aj_18\"", "helpful": [1, 1], "title": "Ballet Dress-Up Fairy Tutu", "url": "http://rads.stackoverflow.com/amzn/click/0000031887", "brand": "Boutique Cutie", "reviewText": "This was a really cute tutu the only problem is that it was super short on my 5 yr old daughter. Other than that it was really adorable.", "overall": 4.0, "summary": "Really Cute but rather short.", "unixReviewTime": 1337990400, "reviewTime": "05 26, 2012"} 
+1

两者都是有效的JSON结构。相结合,他们不是。 –

回答

2

如果您想在同一个json文件中使用它们,您必须将它们组合为[{Obj 1},{Obj 2}]。否则,json文件将包含两个字典对象,并且它只能有一个顶级对象。

+0

如果它无效,为什么我的代码在解析文件时工作:“JSONObject doc = new JSONObject(docString);”?这完美的作品。 – user697911

+0

完美的作品,当它们在同一个文件中时是否解析两个对象? –

+0

是的,我可以解析整个文件,其中包含许多{}像上面的对象。 – user697911