Q:

sending list of values in JSONObject

public class sample {
    public static void main(String[] args) {
        List<String> sList = new ArrayList<String>();
        JSONObject inputJsonObj = new JSONObject();
        try {

            inputJsonObj.put("ipaddress","10.254.27.12");

            inputJsonObj.put("ipaddress", "10.253.140.116");

            Client client = Client.create();
            WebResource webResource = client
                    .resource("http://10.85.249.29:8080/checkRest/CheckxARC/getVersion");
//             

            ClientResponse response = webResource.type("application/json")
                    .post(ClientResponse.class, inputJsonObj.toString());
            String output = response.getEntity(String.class);

            System.out.println(" op--->"+output);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

I have created a client side code for calling restful webservices. Previously when I was sending single ipaddress it was working perfectly.Now when i am trying to send more than 1 IPadrresses I am being able to proceed.Can anyone suggest me how can I proceed it?

A:

you could use a JSONArray. In it, you will store all your ip adress.
Then, you add the array to your JSONObject using the put method.
It would look like:
JSONArray array = new JSONArray();
array.put("10.254.27.12");
array.put("10.254.27.123");

JSONObject inputJsonObj = new JSONObject();
inputJsonObj.put("ipaddresses",array);
// Using ipaddresses as there are many addresses
// The rest of the code stays the same

Note: sorry, I did not add much time to test it, but the logic and objects are there. :)
Cheers

