简体   繁体   English

为什么我在 JSON.parse 错误时收到 Unexpected end of JSON input

[英]Why do I get an Unexpected end of JSON input at JSON.parse error

When I run the following ejs code using npm start , it displays syntax error.当我使用npm start运行以下 ejs 代码时,它显示语法错误。

Here is the code.这是代码。 I think in my guess, the error is related to the arrow(=>).我认为在我的猜测中,错误与箭头(=>)有关。

<% JSON.parse(documents).forEach(document => { %>
    <a class="list-group-item list-group-item-action" id="<%= document.Key %>" data-bs-toggle="tab"
      href="#list-<%= document.Key %>" role="tab" aria-controls="list-<%= document.Key %>" style="min-width: 200px;"><%= document.Key %></a>
<% }) %>

Here is the exact error displayed when I run localhost:3000/ on the browser这是我在浏览器上运行 localhost:3000/ 时显示的确切错误

SyntaxError: /javascript/views/pages/dashboard.ejs:14
    12|     <div class="list-group" id="list-tab" role="tablist" style="margin-top: 10px;">
    13| 
 >> 14|     <% JSON.parse(documents).forEach(document => { %>
    15|         <a class="list-group-item list-group-item-action" id="<%= document.Key %>" data-bs-toggle="tab"
    16|           href="#list-<%= document.Key %>" role="tab" aria-controls="list-<%= document.Key %>" style="min-width: 200px;"><%= document.Key %></a>
    17|     <% }) %>

Unexpected end of JSON input at JSON.parse (<anonymous>)

Replace JSON.parse(documents).forEach(document.. into documents.forEach(documentJSON.parse(documents).forEach(document..替换为documents.forEach(document

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript JSON.parse throw意外的JSON输入错误结束 - javascript JSON.parse throw Unexpected end of JSON input error JSON.parse localStorage输入错误意外结束 - JSON.parse localStorage unexpected end of input error JSON.parse() 返回意外的输入结束 - JSON.parse() Returning Unexpected end of input SyntaxError:JSON.parse 处的 JSON 输入意外结束(<anonymous> )</anonymous> - SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) 未捕获的语法错误:JSON.parse 处的 JSON 输入意外结束 - Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse 在JSON.parse中获取“ JSON输入意外结束” - Getting "Unexpected end of JSON input at JSON.parse 未捕获的 SyntaxError:JSON.parse 处的 JSON 输入意外结束(<anonymous> ) - Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) 未捕获的语法错误:JSON.parse 处的 JSON 输入意外结束(<anonymous> )</anonymous> - Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse(<anonymous>) JSON.parse 处的 JSON 输入意外结束(<anonymous> )</anonymous> - Unexpected end of JSON input at JSON.parse (<anonymous>) 语法错误:JSON.parse 处的 JSON 输入意外结束(<anonymous> ) on(&quot;数据&quot;) - SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) on("data")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM