Is it worth the effort to try to reduce JSON size?

后端 未结 5 1973
遥遥无期
遥遥无期 2020-12-24 02:21

I am submitting relatively lots of data from a mobile application (up to 1000 JSON objects), that I would normally encode like this:

[{
    id: 12,
    score         


        
5条回答
  •  醉酒成梦
    2020-12-24 03:13

    Since you're using this on a mobile device (you mention 3G), you might actually want to care about size, not readability. Moreover, do you frequently expect to read what is being transmitted over the wire?

    This is a suggestion for an alternate form.

    ProtoBuf is one option. Google uses it internally, and there is a ProtoBuf 'compiler' which can read .proto files (containing a message description) and generate Java/C++/Python serializers/deserializers, which use a binary form for transmission over the wire. You simply use the generated classes on both ends, and forget about what the object looks like when transmitted over the wire. There is also an Obj-C port maintained externally.

    Here is a comparison of ProtoBuf against XML, on the ProtoBuf website (I know XML is not what you use, still).

    Finally, here is a Python tutorial.

提交回复
热议问题