json - Better way to send data to server -


i have 2 ways in can send data(json string) server.

1)map<key,list>

eg. {"components":["ab","bc","cd"],"values":[1,2,3]}

this represents value of component "ab" 1.

2) map<key,values>

eg. {"ab":1,"bc":2,"cd":3}

now above example of 3 components want send thousands of components 1 more scalable in terms of size , performance.

if feel missed details feel free ask.

server side have if want value key "bc":

option 1: {"components":["ab","bc","cd"],"values":[1,2,3]}

string json = [...] // got json client myjsonobject jo = new gson().fromjson(json, myjsonobject.class);  int index = jo.getcomponents().indexof("bc"); // o(n) int value = jo.getvaluess().get(index);       // o(1) 

option 2: {"ab":1,"bc":2,"cd":3}

string json = [...] // got json client myjsonobject jo = new gson().fromjson(json, myjsonobject.class);  int value = jo.get("bc");       // o(1) ~ o(n) 

i believe option 2 better because of better performance. simpler , more readable option 1. differences in bandwidth can neglected.

but you should decide solution better your application.


Comments