am trying to count all the duplicate data from a json file, but i dont get the right count of the data, im thinking to arrange the data before i add it to a list but its possible to arrange json data? what i think for the ouput :
component : pensil : 5
pen : 1
here is my codes. some tips guys thanks.
public Main1(){
BufferedReader br = null;
JSONParser parser = new JSONParser();
String inputline,aa;
List<String> list = new ArrayList<String>();
try {
br = new BufferedReader(new FileReader("/Users/lyod/Documents/sample.json"));
try {
String id = null,component = null,title = null,lat = null,
lng = null, cost = null, status = null;
while ((inputline = br.readLine()) != null) {
JSONArray a = (JSONArray) parser.parse(inputline);
for (Object o : a) {
JSONObject sample = (JSONObject) o;
id = (String) sample.get("id");
component = (String) sample.get("component");
list.add(component);
aa =(component+" " + Collections.frequency(list, component));
}
System.out.println(aa);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}