I have my client as an android program. I take the user details from the the user and send it to the server for storing it in the database. I have used a URLConnection object to send data to the servlet. I am sending the user details in using ‘writeObject’.
URL url = new URL("http://10.0.2.2:8080/hello");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
String s="check"+","+susername+","+password+","+email;
out.writeObject(s);
out.flush();
out.close();
As you see I have seperated the details with “,”. In the servlet, I used string .split() function to retrieve back the values. It is working perfectly fine. Except that I see and hear people telling me to send it in json format because it is faster. I don’t understand how? The content is going to be the same right? Is it completely different protocol for transfering data? How should it be used? please suggest some links if you think this is a very trivial question.
JSON is only a Data format, it uses JavaScript notation to represent data records as objects. In the case you describe, you’d be using HTTP to send the same data but in different format, so i don’t think there would be a performance enhancement at all.
For the 3 tokens that you’re sending over the wire, your comma-separated values are just fine. But if you want to send information of 50 users with 15 attributes each, maybe JSON is an option (and it has lots of frameworks/API’s to work with)