Mr_Hmp
Mr_Hmp

Reputation: 2535

Json.put() function puts double quotes automatically

I am preparing a json object to be sent over a webservice , I am trying to put a list of String in the object, Something like this:

["24348f08-92f4-481a-9a36-ed0d533ca4f3", "24348f08-92f4-481a-9a36-ed0d533ca4f3"]

What i have done:

    sendData.put("SpecializationAlert",Specialization);

sendData is a json object and Specialization is a String array, the result when i log this is:

"[\"24348f08-92f4-481a-9a36-ed0d533ca4f3\",\"24348f08-92f4-481a-9a36-ed0d533ca4f3\"]"

Upvotes: 3

Views: 1492

Answers (1)

allprog
allprog

Reputation: 16790

Specialization is put in the JSON as a toString()-ed object. You may create a JSONArray from it first and then include it in the JSONObject:

sendData.put("SpecializationAlert",new JSONArray(Arrays.asList(Specialization)));

Upvotes: 2

Related Questions