- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 Windows 10 上,我使用 node.js,我使用 node-jq@1.10.0(目前最新版本)
我想用 jq 从 JSON 中检索一些信息。所以我使用带有“json”作为选项参数的 jq.run 函数。但它抛出一个错误,我知道我的查询很好,并且我的所有代码都没有以“let AllKOMoves = ...”开头的行。
我的 JSON 格式正确,我在 JMES 路径中尝试了这个程序,它运行良好,所以 JSON 没有问题。我做了一些研究,有人说我的操作系统不能支持太长的请求。我想准确地说,我的 JSON 重 6Mo。
我在互联网上做了一些研究,其中一些在这个网站上谈论“未指定 .catch(…)”:here这是关于太长查询的话题:here
这是我的代码,我将 const jq = require('node-jq');
放在了异步函数之外。
(async ()=>{
let name = "abomasnow";
const fileContent = fs.readFileSync(`./Pokemon with move CSV/Queries/nonStatusMove/${name}nonStatusMove.csv`);
let pokemonSubject = JSON.parse(await jq.run(`. | map(select(.name == "${name}"))[0]`, './nameBSTypeAbilityWeight.json'));
var allMoves = moveToJSON(fileContent);
let AllKOMoves = await jq.run(`. | map(select(.Moves | map(select(.Max == 100)) | length > 1)) | map({Nature: .Nature, EV: .EV, Moves: [.Moves | map(select(.Max == 100))[] | .Move], MovesCount: .Moves | length})`,getAllInflictedDamage(pokemonSubject, allMoves, pokemonJSON[0]),{ input: 'json' })
console.log(AllKOMoves);
})();
下面是这部分代码 getAllInflictedDamage(pokemonSubject, allMoves, pokemonJSON[0])
生成的 JSON 示例:
[
{
"Opponent":"abomasnow",
"Move":"wood-hammer",
"Min":16.15,
"Max":19.25,
"Crit":28.88
},
{
"Opponent":"abomasnow",
"Move":"round",
"Min":15.84,
"Max":18.94,
"Crit":28.26
}
]
这是变量 allMoves
中包含的 JSON 示例:
[
{
"name":"bulldoze",
"accuracy":"100",
"category":"physical",
"power":"60",
"priority":"0",
"target":"all-other-pokemon",
"type":"ground"
},
{
"name":"frost-breath",
"accuracy":"90",
"category":"special",
"power":"60",
"priority":"0",
"target":"selected-pokemon",
"type":"ice"
}
]
我期待我的 JSON 的内容,但它抛出了这个错误消息:
(node:21792) UnhandledPromiseRejectionWarning: Error: spawn ENAMETOOLONG
at ChildProcess.spawn (internal/child_process.js:366:11)
at Object.spawn (child_process.js:538:9)
at C:\Users\adela\node_modules\node-jq\lib\exec.js:24:43
at new Promise (<anonymous>)
at exec (C:\Users\adela\node_modules\node-jq\lib\exec.js:20:10)
at C:\Users\adela\node_modules\node-jq\lib\jq.js:24:24
at new Promise (<anonymous>)
at Object.run (C:\Users\adela\node_modules\node-jq\lib\jq.js:19:10)
at C:\Users\adela\node_code\calcDamage1forAll.js:757:28
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21792) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:21792) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
通常我的代码应该像这样检索信息:
[
{
"Nature":"brave",
"EV":[
4,
0,
0,
0,
252,
252
],
"Moves":[
"focus-punch",
"natural-gift-fire90",
"natural-gift-fire100",
"natural-gift-fire80"
],
"MovesCount":4
},
{
"Nature":"brave",
"EV":[
0,
252,
252,
4,
0,
0
],
"Moves":[
"natural-gift-fire90",
"natural-gift-fire100",
"natural-gift-fire80"
],
"MovesCount":3
}
]
编辑:如果我只这样做:
let AllKOMoves = await jq.run(`.`,getAllInflictedDamage(pokemonSubject, allMoves, pokemonJSON[0]),{ input: 'json' })
它也给我同样的错误!
EDIT2:如果我这样做:
let AllKOMoves = await jq.run(`.`,{"foo":"bar"},{ input: 'json' })
它工作得很好!通过一些研究,我认为它只是关于 json 的大小,因为我的 json 大小 ~12Mo,我尝试使用 300 Ko json 它也不起作用所以我认为我的 json 太大了。
我现在的问题是,是否存在其他解决方案可以像第一个答案中提出的那样创建临时文件...
最佳答案
编辑:
由于这个问题,现在已经在 node-jq 1.10.0 ( pull #191 ) 中重新检查并解决了这个问题,因此请确保 node-jq 的版本是最新的您的项目的依赖项应该可以防止出现此错误。
node-jq 1.10.0 之前的背景(或正在研究 ENAMETOOLARGE 问题的人员)
input:
除了'file' 的问题在于它 gets translated by node-jq versions before 1.10.0进入命令行,如 jq --null-input '[json] | [filter]'
因此您的 JSON 和过滤器组合必须小于您的操作系统可接受的最大单个参数和/或总参数限制,在 Windows 上这可能小至 8192 字节。 (对于 128-256k 左右的参数,大多数 UNIX 克隆应该失败并返回 an E2BIG error instead。)
要通过早期版本的 node-jq 将大量数据传递给 jq 而不是直接通过命令行参数,您需要写入一个名称以 .json 结尾的临时文件以使用 {input:file}
如果它很大。
虽然理论上,您可以为文件提供一个 []
数组,让 jq 通过 stdin 等待数据,node-jq
包装子进程,所以它会丑陋地处理它的标准输入。因此,它需要修复,或者需要编写一个备用包装器以通过标准输入将数据传递给 jq,例如:
child_process.spawn...
process.stdin.write('myJsonAsAstring')
process.stdin.end()
更多讨论可见原文node-jq issue .
关于javascript - 如何在 javascript 中修复 "Error: spawn ENAMETOOLONG"(可能由 jq 引起)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166113/
这很可能是我的语法错误,因为我对在 C++ 中使用多个文件和结构(特别是将结构传递给函数)还很陌生。这是三个文件: 主要.cpp: #include #include #include #inc
我有 TypeScript NestJS 项目。 我需要验证传入的 DTO 到我的 API。它可以被描述为“创建项目”,其中我们有建筑类型(房屋、公寓、花园),并根据该类型我们需要定义: 房屋:楼层包
是否可以从可用于泛型参数的可能类型集中排除特定类型?如果是如何。 例如 Foo() : where T != bool 将意味着除了类型 bool 之外的任何类型。 编辑 为什么? 以下代码是我尝试强
我的 WebGL 体积光线转换应用程序即将完成。但是我发现了一个问题。我必须通过 2D 纹理模拟 3D 纹理。这不是问题。我正在用小切片创建一个巨大的纹理。巨大纹理的尺寸约为 4096x4096 像素
我正在处理的网页上显示了一个返回顶部按钮。当您向下滚动时,有时单击它时,它会跳到顶部,然后跳回您在页面上的位置,然后像预期的那样平滑滚动到顶部。请记住,它并不总是这样做。这只是一个滞后或故障问题还是我
我对此还很陌生,所以请耐心等待。 我有一个类,它具有三个属性:几个整数和一个用户定义对象的集合。 public class Response { public int num1 { get;
我正在制作一款平台游戏,让玩家每 30 毫秒跳跃一次,并向上添加少量的力。我想我应该使用多线程,因为我之前已经做过一些,而且看起来很简单。无论如何,我尝试了这个: public void jump()
是否可以从可能的类型集中排除特定类型,这些类型可以在泛型参数中使用?如果是这样的话。 例如 Foo() : where T != bool 表示除 bool 类型之外的任何类型。 编辑 为什么? 以下
我正在尝试在单个查询中实现内部和外部联接,我不确定我的做法是正确还是错误,因为我不太擅长查询。 就这样吧。 我有以下表格。 hrs_residentials hrs_residential_utili
关于 my website ,有一段代码可以向页面添加几个元素。这段代码不是我可以编辑的东西,而且我对它放置这些元素的位置不满意,因为它弄乱了我的一些布局。所以我想出了一个小的 jQuery 来将它们
一位客户希望我创建一个数据集,如下所示。我不知道这是否可能或合乎逻辑。 我有表parent: id name ------- ------- 1 parent1 2
这可能吗?google 好像没有这方面的资料.. 这样,如果用户在另一个网站上播放视频或歌曲,我的音量就会自动减小 最佳答案 不,这是不可能的。 如果可能的话,它必须是特定于浏览器的,但我不认为这种情
所以我正在尝试制作响应式页面。问题是为什么它归结为移动数据需要位于列表中。 我会用一些示例代码来解释 所以这可能是桌面上的输出 option1
当您将鼠标悬停在a 元素 上时,是否可以删除url? 这就是我的意思: 最佳答案 一种选择是使用一些 JavaScript。 删除 href=来自 的属性标签,取而代之的是 onclick=...
我已经考虑了几个小时,但我无法取得太大进展。它是这样的: You have an array of size n and q queries. Each query is of the form (l
我一直在尝试编写一个脚本来强化 android。我没有成功! 我正在通过模拟器运行一个 AVD,并且已经用我加载的 android shell 和 bash shell 试过了。正如您将在下面看到的那
Private Sub Workbook_Open() Dim WBname As String WBname = ThisWorkbook.name If Not InStr(WBname, "te
Spark 2.0.0-预览版 我们有一个应用程序使用了相当大的广播变量。我们在大型 EC2 实例上运行它,因此部署处于客户端模式。广播变量是一个巨大的 Map[String, Array[Strin
我正在尝试从此link中提取摘要。但是,我无法仅提取摘要的内容。到目前为止,这是我完成的工作: url <- "http://www.scielo.br/scielo.php?script=sci_a
我的主页中有一个iframe。 iframe页面中有一个modalpopup。因此,当显示modalpopup时,modalpopup的父级是iframe主体和主页父级主体。因此,覆盖层仅覆盖ifra
我是一名优秀的程序员,十分优秀!