0

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.

Ashwin
  • 10,386
  • 29
  • 103
  • 172

1 Answers1

0

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)

Carlos Gavidia-Calderon
  • 6,905
  • 8
  • 30
  • 58
  • Sending 50 users' details would require an array and I think in json also probably you need a json array. is json array serializeable. How would you send the json array. – Ashwin Feb 21 '12 at 14:40
  • As i said, JSON is only a data format. On the wire is only plain text with JavaScript syntax. Think of it as a lighter XML. To work with JSON you should use a framework that transforms your Java Objects to a JSON Document. I'm not an Android Developer, but this post seems to show you how: http://stackoverflow.com/questions/6218143/android-post-json-using-http – Carlos Gavidia-Calderon Feb 21 '12 at 14:51