gpt4 book ai didi

javascript - 尝试解析大型 JSON 对象并提取数据,但不断收到意外的 token 错误

转载 作者:行者123 更新时间:2023-12-02 14:49:05 25 4
gpt4 key购买 nike

我有一个文件,sample.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 对象的示例,我想遍历该对象并从每个数组对象中选择设施名称(不确定这是否是正确的术语),然后将每个设施名称写入新文件。

我知道我需要加载 JSON 对象,然后对对象的长度执行 for 循环。现在我只是想加载sample.JSON 文件。这是到目前为止我的代码:

var data = require('./campSample.JSON');
var fs = require('fs');

console.log(JSON.parse(data));

尝试使用节点运行此命令总是给出语法错误:意外的标记:,引用“结果集”中的冒号:{

我不知道为什么会这样。我使用 JSON 验证器来确认 JSON 是好的。为什么它告诉我这个语法是错误的?

最佳答案

require() 已解析您的 JSON。

您无需执行任何操作。

关于javascript - 尝试解析大型 JSON 对象并提取数据,但不断收到意外的 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36345901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com