I have below json string and would like to access the alsoKnownAs list using Java. I am able to getString for the name, I have tried getJSONArray for alsoKnownAs but it doesn't quite workout
{\"name\":\"moses\",\"alsoKnownAs\":[\"njai\", \"njenga\",\"musa\"]}
I can access the name as below but I can't the equivalent of getString method that would return a list of strings or equivalent of getJSONArray for a list of strings
public static Person parsePersonJson(String json) {
JSONObject currentPerson;
String name;
try {
currentPerson = new JSONObject(json);
// so I can access the name like
name = currentPerson.getString("name");
//I was trying this to get the list but figure out I was using a list of json objects, so not how to get the list of stings
JSONArray arrayKnownAs = names.getJSONArray("alsoKnownAs");
List<String> alsoKnownAs= new ArrayList<>();
for (int i = 0, l = arrayKnownAs.length(); i < l; i++) {
String origin;
origin = arrayKnownAs[i];
alsoKnownAs.add(origin);
}
Person thisPerson = new Person(
//I instantiate person object here
);
return thisPerson;
} catch (org.json.JSONException e) {
// error
}
return null;
}