Skip to content

表达式常见问题(Expressions common issues)#

以下是与表达式相关的一些常见错误和问题,以及解决或排查它们的步骤。

🌐 Here are some common errors and issues related to expressions and steps to resolve or troubleshoot them.

项目 0 中的“JSON 输出”包含无效的 JSON(The 'JSON Output' in item 0 contains invalid JSON)#

当你使用 JSON 模式但未提供有效的 JSON 对象时,会发生此错误。根据 JSON 对象的问题,错误有时会显示为 The 'JSON Output' in item 0 does not contain a valid JSON object

🌐 This error occurs when you use JSON mode but don't provide a valid JSON object. Depending on the problem with the JSON object, the error sometimes display as The 'JSON Output' in item 0 does not contain a valid JSON object.

要解决此问题,请确保你提供的代码是有效的 JSON:

🌐 To resolve this, make sure that the code you provide is valid JSON:

  • 使用 JSON 验证器 检查 JSON。
  • 检查你的 JSON 对象是否引用了未定义的输入数据。如果传入的数据不总是包含相同的字段,可能会出现这种情况。

无法获取表达式的数据(Can't get data for expression)#

当 n8n 无法获取表达式引用的数据时,会发生此错误。通常,这种情况发生在前一个节点尚未运行时。

🌐 This error occurs when n8n can't retrieve the data referenced by an expression. Often, this happens when the preceding node hasn't been run yet.

这种情况的另一种变体可能会显示为 Referenced node is unexecuted。在这种情况下,该错误的完整文本将告诉你哪个节点在此格式下未执行:

🌐 Another variation of this may appear as Referenced node is unexecuted. In that case, the full text of this error will tell you the exact node that isn't executing in this format:

一个表达式引用了节点“<node-name>”,但该节点尚未执行。请更改表达式,或重新连接你的工作流以确保该节点先执行。

要开始故障排除,请测试工作流直至指定节点。

🌐 To begin troubleshooting, test the workflow up to the named node.

对于使用 JavaScript 或其他自定义代码的节点,你可以通过检查以下内容来判断之前的节点是否已执行,然后再尝试使用其值:

🌐 For nodes that use JavaScript or other custom code, you can check if a previous node has executed before trying to use its value by checking the following:

1
$("<node-name>").isExecuted

例如,这个 JSON 引用了输入数据的参数。如果在未将此步骤连接到其他节点的情况下进行测试,就会显示此错误:

🌐 As an example, this JSON references the parameters of the input data. This error will display if you test this step without connecting it to another node:

1
2
3
{
  "my_field_1": {{ $input.params }}
}

无效的语法(Invalid syntax)#

当你使用的表达式存在语法错误时,会发生此错误。

🌐 This error occurs when you use an expression that has a syntax error.

例如,此 JSON 中的表达式包含尾随句点,这会导致语法错误:

🌐 For example, the expression in this JSON includes a trailing period, which results in an invalid syntax error:

1
2
3
4
{
  "my_field_1": "value",
  "my_field_2": {{ $('If').item.json. }}
}

要解决此错误,请检查你的表达式语法,确保它们符合预期格式。

🌐 To resolve this error, check your expression syntax to make sure they follow the expected format.