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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -