0

I am having a correct JSON String which is made out of an Object A, containing a Set of other Objects B.

When I try to get back this Object now from the JSON String, the Set of Objects B will only have a single entry, instead of all the contained in the JSON String.

Any suggestions, or did I just do something forbidden??

Thanks

Benny
  • 1,435
  • 1
  • 15
  • 33
  • Ok, using Lists instead of Sets helped out! Probably JSON-lib does not support Sets?? Maybe someone can confirm this. – Benny Feb 13 '13 at 16:36
  • I don't know but json-lib is somehow outdated...there are a couple of other libraries out there. For example you might try Genson, but you also have Jackson and Gson. – eugen Feb 13 '13 at 18:13

1 Answers1

0

For those who might fall over it, this solved the problem with the Set:

JSONArray jsonArray = JSONArray.fromObject(object);
JSONObject jsonObject = new JSONObject();
jsonObject.put("data", jsonArray.toString());
Benny
  • 1,435
  • 1
  • 15
  • 33