Monday, 15 August 2011

java - Converting CSV to JSON without ANT or Maven -



java - Converting CSV to JSON without ANT or Maven -

i trying convert csv file json format, have no thought ant or maven. have used apache poi. trying apache poi. there other way that?

and trying do, getting next error --java.lang.classnotfoundexception: org.openxmlformats.schemas.spreadsheetml.x2006.main.ctsheet

// start constructing json.

jsonobject json = new jsonobject(); jsonarray rows=new jsonarray(); ( 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 cells. jsonarray cells = new jsonarray(); ( iterator<cell> cellsit = row.celliterator(); cellsit.hasnext(); ) { cell cell = cellsit.next(); cells.put( cell.getstringcellvalue() ); } jrow.put( "cell", cells ); rows.put( jrow ); }

simple csv can converted json simple java coding follows

first load file using

bufferedreader.readline()

then utilize

string.split(",") // value each line

and write each value output using

bufferedwriter // necessary json braces , quoting

java javascript json apache-poi

No comments:

Post a Comment