java - not able to shuffle a JSONArray -


i trying shuffle jsonarray , subset(jsonarray). example if jsonarray has 5 entries, want generate jsonarray random 3 entries out of 5 in it. below code shuffling jsonarray. problem output jsonarray has backslash() characters introduced before every occurance of double quotes("). not sure why hapening. someone. suggestions on how can pick first 3 random entries of 5 jsonarray

public jsonarray getrandomjsonarray(jsonarray jarray){     list<string> stringarraymaster = new arraylist<string>(arrays.aslist(jarray.tostring()));     collections.shuffle(stringarraymaster);     jsonarray randomjarray = new jsonarray(stringarraymaster);     return randomjarray;  } 

the \ added because " in json has special meaning- end of field. have " in string need escape it. \ used escaping. getting first 3 entries- jsonarray.getstring(0); jsonarray.getstring(1); jsonarray.getstring(2); bonus these should unescaped, since jsonarray knows java doesn't need escape


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -