java - how do i add String array to JSON -
i writing code in servlet gets data database , returns client. having problems inserting array of dates have collected , adding them json object return client.
here code i'm trying keeps giving errors
dates = classdatesdao.getdate(dates); arraylist<string> classdates = new arraylist<string>(); classdates = dates.getclassdates(); response.setcontenttype("application/json"); jsonobject dates = new jsonobject(); dates.put("dates", new jsonarray(classdates));
in ide error on classdates
in jsonarray
the constructor jsonarray(arraylist) undefined
you passing arraylist
instance instead of array
. so, convert list array , pass argument this
dates.put("dates", new jsonarray(classdates.toarray(new string[classdates.size()])));
note : json
api has method signature accepting java.util.collection
. so, using other library or older version
Comments
Post a Comment