首页 > 解决方案 > 为什么我会在 JSON.parse 错误时收到 Unexpected end of JSON input

问题描述

当我使用 运行以下 ejs 代码npm start时,它显示语法错误。

这是代码。我认为在我的猜测中,错误与箭头(=>)有关。

<% 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>
<% }) %>

这是我在浏览器上运行 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>)

标签: javascriptejs

解决方案


推荐阅读