Convert ArrayList to Json in java
Download Jar :
https://www.box.com/s/r2jq0r0ado5tth9k1bef
Download Link:
https://www.box.com/s/edb4kd7n3oqmnveg0lei
Download Jar :
https://www.box.com/s/r2jq0r0ado5tth9k1bef
Download Link:
https://www.box.com/s/edb4kd7n3oqmnveg0lei
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ListToJson {
public static void main(String[] args) throws JSONException {
List<String> list = new ArrayList<String> ();
list.add("Jay");
list.add("Hiren");
list.add("Jignesh");
convertListToJson(list);
}
public static void convertListToJson(List<String> list) throws JSONException{
int size = list.size();
JSONArray obj = new JSONArray();
JSONObject main = new JSONObject();
for(int i=0 ; i<size ; i++){
obj.put(i);
}
main.accumulate("data", obj);
System.out.println(main.toString());
}
}
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ListToJson {
public static void main(String[] args) throws JSONException {
List<String> list = new ArrayList<String> ();
list.add("Jay");
list.add("Hiren");
list.add("Jignesh");
convertListToJson(list);
}
public static void convertListToJson(List<String> list) throws JSONException{
int size = list.size();
JSONArray obj = new JSONArray();
JSONObject main = new JSONObject();
for(int i=0 ; i<size ; i++){
obj.put(i);
}
main.accumulate("data", obj);
System.out.println(main.toString());
}
}
No comments:
Post a Comment