Tag: csv

使用Jackson库直接将CSV文件转换为JSON文件

我使用以下代码: CsvSchema bootstrap = CsvSchema.emptySchema().withHeader(); ObjectMapper mapper = new CsvMapper(); File csvFile = new File(“input.csv”); // or from String, URL etc Object user = mapper.reader(?).withSchema(bootstrap).readValue(new File(“data.csv”)); mapper.writeValue(new File(“data.json”), user); 它在我的IDE中抛出一个错误,说cannot find symbol method withSchema(CsvSchema)但为什么? 我使用了一些例子中的代码。 我不知道写入mapper.reader()因为我想转换任何CSV文件。 如何将任何CSV文件转换为JSON并将其保存到磁盘? 接下来做什么? 例子