-3

I want to send particular data from database and parse into jsonarray and send it to server. I am able to send dummy data directly to server .Can you tell me the way to send data (parsed jsondata ) into server.?

Preeti
  • 21
  • 2

2 Answers2

0

For your approach you should firstly create a array list with all your necessary data send to server. You can parse into json using Jakeson see Example here. Resultant will be your data.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
laxmikant
  • 71
  • 9
0

Firstly you have to put all your data in the arrayList then use this code

private String arrayToJson(ArrayList<HashMap<String, String>> arrayList) {

    //Coverting Arraylist to JsonArray
    List<JSONObject> jsonList = new ArrayList<JSONObject>();
    for (HashMap<String, String> data : arrayList) {

        JSONObject jsonObject = new JSONObject(data);
        jsonList.add(jsonObject);
    }

    JSONArray json_array= new JSONArray(jsonList);

    String json_string= json_array.toString();
}

then you can send this to server. And decode this json_string and retrive your data

Sho_arg
  • 383
  • 3
  • 13