从angularJs读取Json文件导致错误

时间:2015-09-21 11:22:33

标签: json angularjs iis-7

我正在尝试从我的visual studio 2013环境中读取json文件。如下所述,它会抛出一些错误

plnkr

然而,它在import java.awt.BorderLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextArea; public class DataManager extends JFrame { private String students[] = {"John Smith","Ken Hanson","Michael Li","John Andersen","Fiona Harris","Angela Lim","Bob London","Sydney Shield","Tina Gillard", "Ross Brinns","Scott Cairns","Grant Peterson","David Power","Joshua Kane","Alan Newton","Frady Morgan","Quinn Perth"}; private int english[] = {80,52,71,61,39,62,31,46,60,26,77,40,58,38,94,90,97}; private int maths[] = {60,45,77,90,45,55,66,87,31,42,65,55,80,71,51,55,95}; private int total[]; private JButton sortNameButton; private JButton sortTotalButton; private JTextField searchTextField; private JButton statisticsButton; private JButton exitButton; private JTextArea infoTextArea; private JPanel jPan; public DataManager() { super("Data Manager "); jPan = new JPanel(); sortNameButton = new JButton("Sort By Name"); sortTotalButton = new JButton("Sort By Total"); searchTextField = new JTextField("Search"); statisticsButton = new JButton("Statistics"); exitButton = new JButton("Exit"); infoTextArea = new JTextArea(); setLayout(new BorderLayout()); jPan.add(sortNameButton, BorderLayout.NORTH); jPan.add(sortTotalButton, BorderLayout.NORTH); jPan.add(searchTextField, BorderLayout.NORTH); jPan.add(statisticsButton, BorderLayout.NORTH); jPan.add(exitButton, BorderLayout.NORTH); jPan.add(infoTextArea, BorderLayout.CENTER); } public static void main(String[] args) { DataManager frame = new DataManager(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800,600); frame.setVisible(true); } // End of main method. } // End of DataManager class http://plnkr.co/edit/std1ngB40YIJBmC94Zdm?p=preview

上工作正常

有人可以告诉我如何解决这个问题吗?

错误截屏

enter image description here

文件夹结构 enter image description here

enter image description here

2 个答案:

答案 0 :(得分:-1)

您是否正确设置了mime地图?我只看到处理程序映射的截图。

  1. 打开IIS管理器
  2. 显示IIS服务器的属性
  3. 单击MIME类型,然后添加JSON扩展:
    • 文件扩展名:.json MIME
    • 类型:application / json
  4. 返回IIS服务器的属性
  5. 点击Handler Mappings
  6. 添加脚本地图
    • 请求路径:* .json
    • 可执行文件:C:\ WINDOWS \ system32 \ inetsrv \ asp.dll
    • 姓名:JSON
  7. 如果仍然无法正常工作,请删除已完成的脚本地图,并坚持使用mime地图,我不知道你为什么要首先添加脚本地图。

答案 1 :(得分:-1)

我对这个问题做了很多研究,最后解决了:) :)

我也尝试了@James Trotter给出的答案,但没有成功。

我不知道为什么IIS中的MIME不起作用,但是当我在web.config

中添加它时它才起作用

解决方案:

  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>

了解更多信息

Allow loading of JSON files in Visual Studio Express 2013 for Web