0

I have a list of String which I wish to convert to Json.

    ArrayList<String> list = new ArrayList()l
    list.add("IR01");
    list.add("00112");
    list.add("0ID001");

By using list.toString(), getting response string as [IR01,00112,0ID001], but one of my requirement needs to send json string like `"["\IR01","\00112","\0ID001\"]" to StringEntity class.

I don't know how to continue from here. A little help will be appreciated. Thanks.

Aswani
  • 1
  • 2

1 Answers1

0

first i advise you to use List instead of arraylist In fact, everywhere you need to declare a reference variable, you should always use the supertype, like Map for passing HashMap, Set for giving HashSet, and List for passing ArrayList, LinkedList, or Vector. And now your answere

String json = new Gson().toJson(list);
CLAIN Cyril
  • 123
  • 9