【发布时间】:2020-05-14 19:49:00
【问题描述】:
您好,我正在尝试使用名为 csvReader 的依赖项将 CSV 文件转换为 JSON 数组,但是当我运行代码时,它会错误地打印出 JSON 响应,我知道为什么有人能够指出我的正确之处方向。
@GetMapping("/convert")
public List<List<String>> convertCSV() throws FileNotFoundException {
List<List<String>> records = new ArrayList<List<String>>();
try (CSVReader csvReader = new CSVReader(new FileReader("C:/Download/cities.csv"));) {
String[] values = null;
while ((values = csvReader.readNext()) != null) {
records.add(Arrays.asList(values));
}
} catch (IOException e) {
e.printStackTrace();
}
return values;
}
【问题讨论】:
-
输出有什么问题?输出由字符串数组组成,我希望查看代码,因为
convertCSV返回List<List<String>>。 -
你能解释一下这个
prints out the JSON response incorrectly吗?什么不正确? -
我需要它来打印“latD”:“41”、“LatM”:“5”、“LatS”:“59”、“NS”:“N”等...我只需要将类型从列表更改为数组,为了获得更多上下文,我需要一个 Angular 7 前端才能遍历数组
标签: java spring-boot