我有一个文件,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验证器? –