我试图将CSV文件转换为JSON格式,但我不知道ANT或MAVEN。我使用过Apache POI。我正在尝试使用Apache POI来做到这一点。有没有其他方法可以做到这一点?在没有ANT或Maven的情况下将CSV转换为JSON
,这就是我要怎样做,但得到以下错误 --java.lang.ClassNotFoundException:org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet
//开始构建JSON。
JSONObject json = new JSONObject();
JSONArray rows=new JSONArray();
for (Iterator<org.apache.poi.ss.usermodel.Row> rowsIT = sheet.rowIterator(); rowsIT.hasNext();)
{
org.apache.poi.ss.usermodel.Row row = rowsIT.next();
JSONObject jRow = new JSONObject();
// Iterate through the cells.
JSONArray cells = new JSONArray();
for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();)
{
Cell cell = cellsIT.next();
cells.put(cell.getStringCellValue());
}
jRow.put("cell", cells);
rows.put(jRow);
}
是它转换成JSON,还有另一种方式来做到这一点。问题回答了。 – Cerbrus 2013-02-14 10:14:06
请发布您的CSV标题,我为您制作了二十行代码...... – Aerospace 2013-02-14 10:14:59