如何让我的JSON更简洁一些? [英] How do I make my JSON less verbose?

查看:147
本文介绍了如何让我的JSON更简洁一些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个Web应用程序和使用JSON的Ajax请求和响应。我有我的地方超过10000对象的数组形式返回一个非常大的数据集到客户的区域。下面是示例的一部分(其被简化有些):

I'm currently developing a web application and using JSON for ajax requests and responses. I have an area where I return a very large dataset to the client in the form of an array of over 10000 objects. Here's part of the example (its been simplified somewhat):

"schedules": [
        {
            "codePractice": 35,
            "codeScheduleObject": 576,
            "codeScheduleObjectType": "",
            "defaultCodeScheduleObject": 12,
            "name": "Dr. 1"
        },
        {
            "codePractice": 35,
            "codeScheduleObject": 169,
            "codeScheduleObjectType": "",
            "defaultCodeScheduleObject": 43,
            "name": "Dr. 2"
        },
        {
            "codePractice": 35,
            "codeScheduleObject": 959,
            "codeScheduleObjectType": "",
            "defaultCodeScheduleObject": 76,
            "name": "Dr. 3"
        }
    ]

正如,你可以想像,一个非常大的数字在这个数组对象时,JSON效应初探规模可能相当大。

As, you can imagine, with a very large number of objects in this array, the size of the JSON reponse can be quite large.

我的问题是,是否有一个JSON stringifier /解析器,将转换成日程表阵列看起来像这是一个JSON字符串:

My question is, is there a JSON stringifier/parser that would convert the "schedules" array to look something like this as a JSON string:

"schedules": [
    ["codePractice", "codeScheduleObject", "codeLogin", "codeScheduleObjectType", "defaultCodeScheduleObject","name"],
    [35, 576, "", 12, "Dr. 1"],
    [35, 169, "", 43, "Dr. 2"],
    [35, 959, "", 76, "Dr. 3"],
]

也就是说,将有一个数组的日程表数组举行的对象数组的键的开始,和所有其他容器阵列将持有的值。

ie, that there would be an array at the beginning of the "schedules" array that held the keys of the objects this array, and all of the other container arrays would hold the values.

我可以,如果我想,做转换在服务器上,解析它在客户端上,但我不知道是否有用于分析一个标准库/字符串化大JSON?

I could, if I wanted, do the conversion on the server and parse it on the client, but I'm wondering if there's a standard library for parsing/stringifying large JSON?

我也可以通过minifier运行它,但我想保持我目前的钥匙,因为他们给应用程序中的一些背景。

I could also run it through a minifier, but I'd like to keep the keys I have currently as they give some context within the application.

我也希望你可以批评我的做法在这里还是建议选择吗?

I'm also hoping you might critique my approach here or suggest alternatives?

推荐答案

HTTP COM pression(即gzip压缩或紧缩)已经正是这么做的。重复的图案,像你的JSON钥匙,被替换的令牌,这样冗长的模式只需要发生一次每个传输。

HTTP compression (i.e. gzip or deflate) already does exactly that. Repeated patterns, like your JSON keys, are replaced with tokens so that the verbose pattern only has to occur once per transmission.

这篇关于如何让我的JSON更简洁一些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆