Javascript:如何在不使用jQuery或AJAX的情况下将JSON对象加载为文件?(复制)

时间:2021-11-05 09:51:00

Possible Duplicate:
How to parse JSON using NodeJS?

可能重复:如何使用NodeJS解析JSON ?

I am running a server. The code is run on the server with Node.js -- never run in a browser.

我正在运行一个服务器。代码在带有节点的服务器上运行。js——永远不要在浏览器中运行。

How can I load a JSON file ("data.json") into javascript code as a javascript object? Should I just use jQuery/AJAX to do this? Is there a simple way with plain js? Thanks in advance! BTW I searched for this on both Google and this website without any clear answers.

如何将JSON文件(“data.json”)加载到javascript代码中作为javascript对象?我是否应该使用jQuery/AJAX来实现这一点?用普通js有什么简单的方法吗?提前谢谢!顺便说一句,我在谷歌和这个网站上搜索了这个,没有任何明确的答案。

1 个解决方案

#1


3  

Have a look at this

看看这个

Read the whole contents of the file, and then just parse it.
Have a look at this question.

读取文件的全部内容,然后解析它。请看这个问题。

#1


3  

Have a look at this

看看这个

Read the whole contents of the file, and then just parse it.
Have a look at this question.

读取文件的全部内容,然后解析它。请看这个问题。