Is it possible using json-simple (and no other additional library) to convert a JSONArray
to an ArrayList<MyObject>
?
I was not able to find code samples in the documentation nor on SO.
This is how I do it at the moment (quite a bit complicated):
for(Iterator iterator = jsonRootObject.keySet().iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
JSONObject jsonEpg = (JSONObject) jsonRootObject.get(key);
JSONArray jsonEpgTags = (JSONArray) jsonEpg.get("tags");
//Iterate tags
for(int i = 0; i < jsonEpgTags.size(); i++) {
JSONObject jsonEpgTag = (JSONObject) jsonEpgTags.get(i);
final String tagId = (String) jsonEpgTag.get("id");
String name = (String) jsonEpgTag.get("name");
EpgJsonTagValue jsonTagValue = new EpgJsonTagValue();
jsonTagValue.tagId = tagId;
jsonTagValue.name = name;
result.add(jsonTagValue);
}
}
My "POJO":
public class EpgJsonTagValue {
private String tagId;
private String name;
public String getTagId() {
return tagId;
}
public void setTagId(String id) {
this.tagId = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return "TagId: " + tagId
+ ", Name: " + name;
}
}