我有一個文件,sample.JSON具有以下內容:試圖通過大量JSON對象分析和提取數據,但不斷收到意外的標記錯誤
{ "resultset": {
"-count": "4904",
"-resultType": "campgrounds",
"result": [
{
"-availabilityStatus": "N",
"-contractID": "GA",
"-contractType": "STATE",
"-facilityID": "530145",
"-facilityName": "A. H. STEPHENS STATE HISTORIC PARK",
"-faciltyPhoto": "/webphotos/GA/pid530145/0/80x53.jpg",
"-latitude": "33.5633333",
"-longitude": "-82.8966667",
"-shortName": "C145",
"-sitesWithAmps": "Y",
"-sitesWithPetsAllowed": "Y",
"-sitesWithSewerHookup": "N",
"-sitesWithWaterHookup": "Y",
"-state": "GA"
},
{
"-availabilityStatus": "N",
"-contractID": "OH",
"-contractType": "STATE",
"-facilityID": "960023",
"-facilityName": "A.W. MARION STATE PARK",
"-faciltyPhoto": "/webphotos/OH/pid960023/0/80x53.jpg",
"-latitude": "39.6336111",
"-longitude": "-82.8747222",
"-shortName": "P023",
"-sitesWithAmps": "Y",
"-sitesWithPetsAllowed": "Y",
"-sitesWithSewerHookup": "N",
"-sitesWithWaterHookup": "N",
"-state": "OH"
},
{
"-availabilityStatus": "N",
"-contractID": "NRSO",
"-contractType": "FEDERAL",
"-facilityID": "72346",
"-facilityName": "ACKER ROCK LOOKOUT",
"-faciltyPhoto": "/webphotos/NRSO/pid72346/0/80x53.jpg",
"-latitude": "43.0523056",
"-longitude": "-122.6456111",
"-shortName": "ARCL",
"-sitesWithAmps": "N",
"-sitesWithPetsAllowed": "Y",
"-sitesWithSewerHookup": "N",
"-sitesWithWaterHookup": "N",
"-state": "OR"
}
] } }
這僅僅是一個大得多的樣本JSON對象,我想要通過並從每個數組對象中選擇facilityName(不知道這是否合適),然後將每個facilityName寫入一個新文件。
我知道我需要加載JSON對象,然後做一個for循環的對象的長度。現在,我只是想獲取sample.JSON文件加載。這是我到目前爲止的代碼:
var data = require('./campSample.JSON');
var fs = require('fs');
console.log(JSON.parse(data));
試圖運行這個與節點一直給我的SyntaxError:意外的標記:,指結腸「的ResultSet」:{
我不知道爲什麼會這樣將會。我使用JSON驗證器來確認JSON是否合適。爲什麼它告訴我這個語法是錯誤的?
你使用了什麼JSON驗證器? –