简体   繁体   中英

Framework for encode redundant field names in JSON objects and decode it in javascript?

I'm retrieving below json object array data from a web service. As you can see Id, ProjectId, Owner fields are repeated for all the objects(I know its JSON convention). But I'm thinking is there any library/framework to minimize that? like when json is serializing serialize the field name to a unicode char and deserialize it in javascript again to readable field name.

[
{
"Id":0,
"ProjectId":"PJ4604",  
"Owner":"SURENJ1", 
},
{
"Id":1,
"ProjectId":"PJ4604",  
"Owner":"SURENJ1",
},
{
"Id":2,
"ProjectId":"PJ4604", 
"Owner":"SURENJ1"
}]

The usual way to do this is to use HTTP compression . When enabled, the server and browser will compress and decompress the data transparently. You don't need anything specific to JSON.

The specifics on enabling it will depend on your HTTP server (and possibly any server side languages you use to generate the JSON).

jQuery's extend does something similar to what you're asking for: http://api.jquery.com/jQuery.extend/

Essentially, it will just keep overwriting the first object with the value of the second, so any repeated fields will be overwritten and merged into a single object with only your unique fields.

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