简体   繁体   English

在现代浏览器中生成并加载JSON转储?

[英]Generate and load JSON dump in modern browsers?

I am writting a Web app that can save or open a JSON object, what's the best practice to make it behave exactly like an offline desktop app? 我正在编写一个可以保存或打开JSON对象的Web应用程序,最佳实践是如何使其表现得完全像脱机桌面应用程序? Should the JSON dump just be in plain text or something? JSON转储应该只是纯文本格式还是其他格式?

Could it function properly even if there is no network connection? 即使没有网络连接,它也能正常运行吗? This means we have to use pure client side Javascript generate a savefile/openfile dialog box. 这意味着我们必须使用纯客户端Javascript生成一个savefile / openfile对话框。

You can use localStorage API of modern browsers to save all your needed data. 您可以使用现代浏览器的localStorage API保存所有需要的数据。

localStorage gives you ability to store offline data, but make sure that your data fits within quota. localStorage使您能够存储脱机数据,但要确保您的数据符合配额。

Also keep in mind that native JSON support can be handy in this case (like JSON.stringify()). 还请记住,在这种情况下,本机JSON支持可能很方便(例如JSON.stringify())。

Here are some links that might be useful: 以下是一些可能有用的链接:

JSON in JS JS中的JSON

localStorage 本地存储

I now have the proper technology to do this: 我现在拥有适当的技术来做到这一点:

  1. open dialogs: http://www.html5rocks.com/en/tutorials/file/dndfiles/ 打开对话框: http : //www.html5rocks.com/zh-CN/tutorials/file/dndfiles/

  2. save JSON data: something like data://application/json;base64,eyJkYXRhIjogImhlbGxvLCBqc29uISJ9 保存JSON数据:类似于data://application/json;base64,eyJkYXRhIjogImhlbGxvLCBqc29uISJ9

  3. native json parse https://developer.mozilla.org/en-US/docs/Using_native_JSON 本地json解析https://developer.mozilla.org/en-US/docs/Using_native_JSON

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

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