Answer the question
In order to leave comments, you need to log in
Problems reading JSON file. How to get rid of "Lexical Error: Unmatched Input."?
Good morning everyone :) Please help me to deal with the error, I broke my whole head. There is a JSON file with the following content (There are only 30 objects in the array, I won't cram everything here).
{
«FileName»:«student»,
«Students»: [
{
«ID»: «1»,
«Fio»: «Акулеев Кирилл Андреевич»,
«Group»: «16-IVT-2»,
«Num»: 10
},
{
«ID»: 2,
«Fio»: «Алексейчик Андрей Александрович»,
«Group»: «16-IVT-2»,
«Num»: 11
}
]
}
public static void main(String[] args) throws FileNotFoundException,
IOException, Exception {
JSONParser parser = new JSONParser();
Object Students = parser.parse(new FileReader("/Users/yuliavorobjeva/Desktop/Students.JSON"));
JSONObject jsonStudents = (JSONObject) Students;
String FileName = (String) jsonStudents.get("FileName");
System.out.printf("%s", FileName);
JSONArray people = (JSONArray)jsonStudents.get("Students");
for(Object o: people){
JSONObject person= (JSONObject)o;
int Id = (int)person.get("ID");
String name = (String) person.get("Fio");
String group = (String) person.get("Group");
int num = (int) person.get("Num");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question