简体   繁体   English

我可以将JSON数据保存在.js页而不是.json文件中吗

[英]Can I save json data in a .js page instead of a .json file

We are building a static app of sorts where a user can publish static pages from our site, download them and install them on their own web server. 我们正在构建一个静态应用程序,用户可以在其中从我们的网站发布静态页面,下载静态页面并将其安装在自己的Web服务器上。 In order to do this we are relying on JSON data which will be stored in json files. 为此,我们依靠将存储在json文件中的JSON数据。 My concern is that we have no way of controlling their servers and I am unclear if their servers will support .json file mime/types. 我担心的是,我们无法控制他们的服务器,我不清楚他们的服务器是否支持.json文件mime / types。

Can we just save the json data in a .js file, instead to avoid this potential problem? 我们可以仅将json数据保存在.js文件中,而不是避免这种潜在问题吗?

Sure. 当然。 Just save it as a variable in JS. 只需将其另存为JS中的变量即可。

var myJsonData = {
    "thing": true,
    "otherThing:" 4
    "fancyArray":[
        "hello",
        "hi",
        "greetings"
    ]
};

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

相关问题 我如何将 js 注册保存到我的 json 文件 - How I can take/save a js signup to my json file 我想使用markdown来安全地保存数据(对于xss)而不是json.stringify()方法 - Node js .I want to use markdown to save the data securely(for xss) instead of json.stringify() method 我无法在 html 页面上显示来自 json 文件的数据 - I can’t display the data from the json file on the html page 我如何将数据存储在 json 文件中连续 discord.js - how can i store data in json file Continuous for discord js 我如何在猫鼬中保存 json 数据 - How can i save json data in mongoose 如何在不刷新页面的情况下使用 js 和 json 保存聊天消息? - How can i save chat messages using js and json without refresh page? 我如何将 json 数据保存到数据库中并在保存后进行 foreach? - How i can save json data into database and to foreach after save? 如何在 JSON 文件中进行更改并稍后在 Python 或 JS 中保存? - How can I make changes in the JSON file and save it later in Python or JS? js 文件中的 Vue-i18n 翻译而不是 json - Vue-i18n translations in js file instead of json 我想从html页面中获取数据并将其作为json数据存储在一个文件中,在node.js中 - i want to take the data from html page and store in a file as json data in node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM