matghazaryan
matghazaryan

Reputation: 5896

how to add string into JsonArray

I am trying to add string values in JsonArray and after that create Json String to send it on server.

I was searching on google but I couldn't find anything helpful. Could anyone tell me how to this? Thanks

 JSONArray list = new JSONArray();
 list.put("Hello");
 list.put("Hey");

After that I want create JSONString

Upvotes: 8

Views: 19417

Answers (2)

Rafael T
Rafael T

Reputation: 15679

Simple:

JSONArray list = new JSONArray();
list.put("Hello");
list.put("Hey");

String jsonString = list.toString()

according to docs it should result in "["Hello", "Hey"]"

Upvotes: 16

Simon Meyer
Simon Meyer

Reputation: 2044

just use

list.toString(2)

this will give you the string in json

Upvotes: 1

Related Questions