DragonWar% 2018-05-27 20:52 采纳率: 0%
浏览 62

JSON文件的用例

I've used JSON a number of times within AJAX requests to perform asynchronous writes/reads of a database. I've been trying to better understand JSON and its uses within different programming environments and one of the questions I've been curious about is: what are the common use cases for JSON as external file (rather than just as an object that is passed within AJAX requests)?

More specifically, what are some use cases in which a .json file would be better suited than simply using temporary JSON objects to pass between AJAX requests? Any insight on this would be much appreciated.

  • 写回答

1条回答 默认 最新

  • 七度&光 2018-05-27 21:12
    关注

    I am not that familiar with AJAX etc., but JSON is so popular that many programming languages support it - not just Java and related languages.

    In itself JSON simply holds information - it's merely a format for storing data.

    It can often be used to transfer data between languages. Personally, I am also using JSON to store my objects to persistent data storages and then later on rebuild the objects alongside the .class schematics. For example, Google created GSON to easily turn objects into JSON and back. Very handy!

    You should also think about: How do you transfer an object from one machine to another?

    To sum it up: It's simple, it doesn't create massive overhead, it's even easy to read. And most important of all: So many tools offer JSON support.

    Edit:

    To show the simplicity of re-building from JSON, here's an example from my game:

    public static Player fromJson(String json) {
        if(json != null && !json.isEmpty()) {
            return gson.fromJson(json, Player.class);
        }
        return new Player(); //no save game present. Use default constructor
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀