I didn't expect this is that complex. But I can't figure out how I can convert my arraylist of custom class to a JSONArray. I understand there is no direct method to do that. So I made arraylist of JSONObjects from my arraylist. Now in order to save this into a JSON file, how can I convert the arraylist of JSONObjects to JSONArray?
2 Answers
Like this:
JSONArray toReturn = new JSONArray();
for(JSONObject object : yourJSONArrayList){
toReturn.put(object);
}
toReturn will then be a JSONArray that has all the JSONObjects from your arraylist of JSONObjects in it.
1 Comment
Tae-Sung Shin
Laughing at myself... As a old .NET developer, I searched add or insert. Thanks!
1 Comment
Tae-Sung Shin
I thought about it before but since our app has relatively large file size, I didn't want to add another 200K. But thanks anyway.