1

I have table called GRN and in that so many columns are there with lots of data.

Now i want to sync that GRN data with the server's database.

So we can say whatever data we have in android app for GRN that i need to insert in server's database during sync.

I know how to pass 1 record in post but i want to pass all the data in post during web service calling from Android app.

How to post data to a webservice using json

In this link we can see how to pass some parameter in post.

Does anybody know?

Community
  • 1
  • 1
user1181940
  • 169
  • 1
  • 1
  • 14
  • use name-value pair to post data on php service from android – KOTIOS Mar 30 '15 at 07:54
  • As you can see http://stackoverflow.com/questions/8520011/how-to-post-data-to-a-webservice-using-json in this link there is already used name value pair and based on that we can pass parameter to web service. But here only one record we can pass. How can i pass multiple record? – user1181940 Mar 30 '15 at 07:57
  • where is code? cannot see it – KOTIOS Mar 30 '15 at 07:58
  • I suggest you do some JSON tutorials. You can pass any number of 'records' in a single string. You can even pass an entire database table or even every table in a database if you wanted to. – Squonk Mar 30 '15 at 08:29

1 Answers1

1

Try putting all the data in a Json string (use a library, like org.json). Then you will need to parse it on the server side.

With org.json, you will simply do something like this:

JSONObject o = new JSONObject();
o.put("key1", "value1");
o.put("key2", "value2");

String dataToSend = o.toString();

To make it an array, do something like this:

JSONArray a = new JSONArray();

for([Some loop]){
    JSONObject o = new JSONObject();
    o.put("key", "value");
    a.put(o);
}

String dataToSend = a.toString();
Kelevandos
  • 7,024
  • 2
  • 29
  • 46