I would like to read from a json file like:
{
"name": "Luis Lopez",
"name": "Armando Guascogne Ursular",
"name": "Brancar Diego"
}
read from the json file and copy the names into an array list. I tried like this:
public List getName() {
try {
Object obj = parser.parse(new FileReader("mypath\name.json"));
JSONObject jsonObject = (JSONObject) obj;
String name = (String) jsonObject.get("name");
for (int i = 0; i<jsonObject.length();i++){
datasource.add(name);
}
} catch (Exception e) {
e.printStackTrace();
}
return datasource;
}
But it returns me the empty list.