0

I have following two string with me

String macId= "484487E3A0AC",484487E3FG55,484487E3A0FG,484487HJKL90,484487EKLJK9;

String movieList="Cast Away";

I want to send it to my server as json Object, I am able to achieve it when I send it as single object :

EX:

String macId= "484487E3A0AC";
String movieList="Cast Away";

JSONObject json = new JSONObject();
json.accumulate("title", movieList);
json.accumulate("mac", macId);
httppost.setEntity(new StringEntity(json.toString()));
httpclient.execute(httppost);

finally the json data which I am sending looks like this :

{"mac":"484487E3A0AC","title":"Cast Away"}

Now I have a requirement where My macId is a list (there might be around 10 macId) , where as the movieList will be same . What will be the most optimized way to convert it to json object . Server side coding reads the data as :

{"mac":"......","title":"......"}

So got to convert it accordingly , Please provide some solution as how to club it together

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Android4Fun
  • 570
  • 4
  • 18
  • 1
    There's not enough information here - do you want `{"mac":"1,2,3,4,5", "title":"a,b,c,d,e"}` or do you want `[{"mac":"1","title":"a"},{"mac":"2","title":"b"}...]`? If the second, look up [JSONArray](http://developer.android.com/reference/org/json/JSONArray.html) - you want to create an array of objects. – Ken Y-N Sep 29 '14 at 03:08
  • Hi I want the final out put as--{"mac":["1,2,3,4,5"], "title":"a"} – Android4Fun Sep 30 '14 at 13:55

0 Answers0