Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json.put() function puts double quotes automatically

Tags:

json

android

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\"]"

like image 593
Mr_Hmp Avatar asked Feb 14 '26 07:02

Mr_Hmp


1 Answers

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)));
like image 113
allprog Avatar answered Feb 16 '26 22:02

allprog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!