2017-08-11 324 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