简体   繁体   中英

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. In order to do this we are relying on JSON data which will be stored in json files. 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.

Can we just save the json data in a .js file, instead to avoid this potential problem?

Sure. Just save it as a variable in JS.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM