Javascript Express.js:Can';t在json文件中设置正确的数据格式

Javascript Express.js:Can';t在json文件中设置正确的数据格式,javascript,express,ejs,Javascript,Express,Ejs,我有一个包含数据的json文件,应该以以下格式加载到数组: var jobs = [ { ID: 'grt34hggdggf', Employer: 'A1', Title: 'tobi1', Location: 'Los Angeles, CA', Department: 'department', OpeningDate: '2012-12-26T01:29Z', ClosingDate: '2013-04-26T01:29Z', MinSalary: '30000', MaxSalar

我有一个包含数据的json文件,应该以以下格式加载到数组:

var jobs = [
  { ID: 'grt34hggdggf', Employer: 'A1', Title: 'tobi1', Location: 'Los Angeles, CA', Department: 'department', OpeningDate: '2012-12-26T01:29Z', ClosingDate: '2013-04-26T01:29Z', MinSalary: '30000', MaxSalary: '60000', Description: 'bla-gghrf-bla' },
  { ID: 'grt34hgwerwgf', Employer: 'A2', Title: 'tobi2', Location: 'Los Angeles, CA', Department: 'department', OpeningDate: '2012-12-26T01:29Z', ClosingDate: '2013-04-26T01:29Z', MinSalary: '30000', MaxSalary: '60000', Description: 'bla-gghrf-bla' }
];
因此,这种格式适合我,并且适用于视图。 哪种格式应该包含我的json文件。我尝试以下方法:

{
    "jobs":[
  { "ID": "grt34hggdggf", "Employer": "A1", "Title": "tobi1", "Location": "Los Angeles, CA", "Department": "department", "OpeningDate": "2012-12-26T01:29Z", "ClosingDate": "2013-04-26T01:29Z", "MinSalary": "30000", "MaxSalary": "60000", "Description": "bla-gghrf-bla" },
  { "ID": "grt34hggdggf", "Employer": "A2", "Title": "tobi1", "Location": "Los Angeles, CA", "Department": "department", "OpeningDate": "2012-12-26T01:29Z", "ClosingDate": "2013-04-26T01:29Z", "MinSalary": "30000", "MaxSalary": "60000", "Description": "bla-gghrf-bla" }

  ]
}
但是,当我尝试在视图中执行“forEach”时,我得到了一个错误:

TypeError: F:\tmp\express-master\examples\ejs\views\result.html:5
    3| 
    4| <table>
 >> 5|   <% jobs.forEach(function(job){ %>
    6|     <tr>
    7|         <td>
    8|             <a href="/job/<%= job.ID %>"><%= job.Title %></a>

Object #<Object> has no method 'forEach'
TypeError:F:\tmp\express master\examples\ejs\views\result.html:5
3| 
4| 
>> 5|   
6|     
7|         
8|             
对象#没有方法“forEach”

所以,json文件的格式似乎与预期不同。如何正确操作?

我在我的案例中找到了正确的格式:

[
  { "ID": "grt34hggdggf", "Employer": "A1", "Title": "tobi1", "Location": "Los Angeles, CA", "Department": "department", "OpeningDate": "2012-12-26T01:29Z", "ClosingDate": "2013-04-26T01:29Z", "MinSalary": "30000", "MaxSalary": "60000", "Description": "bla-gghrf-bla" },
  { "ID": "fgert", "Employer": "A2", "Title": "tobi2", "Location": "Los Angeles, CA", "Department": "department", "OpeningDate": "2012-12-26T01:29Z", "ClosingDate": "2013-04-26T01:29Z", "MinSalary": "30000", "MaxSalary": "60000", "Description": "bla11-ggh777rf-bla" }
]

这是在Node.js代码中发生的还是您正在使用其他任何东西,如果您正在使用html文件中可以看到的nodejsa,请尝试我的答案。但没关系