// bitte den Code zu finden unter .I nicht in der Lage ist Objektkarte in jsonwie konvertieren Liste der Karte zu json in java
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("readCsv")
public @ResponseBody String readCsvservice(@Context ServletContext servletContext) throws Exception {
String csvFile = System.getProperty("user.dir") + "/resources/branch_profitability.csv";
String line = "";
String cvsSplitBy = ",";
HashMap<String, String> branch = new HashMap<>();
List<Map> branchList = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
br.readLine();
while ((line = br.readLine()) != null) {
// use comma as separator
String[] country = line.split(cvsSplitBy);
branch.put("Zone", country[0]);
branch.put("State", country[1]);
branch.put("City", country[2]);
branch.put("Location", country[3]);
branch.put("brach", country[4]);
branch.put("Employee", country[5]);
branch.put("EOP", country[6]);
branchList.add(branch);
}
} catch (IOException e) {
e.printStackTrace();
}
ObjectMapper objectMapper = new ObjectMapper();
// try1
String jsonMap = objectMapper.writeValueAsString(branchList);
// try2
String json = new Gson().toJson(branchList);
return json;
}
Was ist das Problem? – petul
Ich habe try1 und try2 kommentiert das ich dann auch verwendet habe ich bin nicht in der Lage zu konvertieren Liste
Es sollte funktionieren, geben Sie eine Reihe von JSON-Objekte. Ist es nicht in dem Format, das Sie erwarten würden? Hast du eine Ausnahme? – petul