List of usage examples for org.json.simple JSONWriter toString
public String toString()
From source file:cc.siara.csv_ml_demo.MainActivity.java
/** * Transforms csv_ml to JSON Object//from w ww.j a v a 2s . co m */ void toJSON() { EditText etInput = (EditText) findViewById(R.id.etInput); CheckBox cbPretty = (CheckBox) findViewById(R.id.cbPretty); MultiLevelCSVParser parser = new MultiLevelCSVParser(); try { JSONObject jo = parser.parseToJSO(new StringReader(etInput.getText().toString()), false); String ex_str = parser.getEx().get_all_exceptions(); if (ex_str.length() > 0) { Toast.makeText(getApplicationContext(), ex_str, Toast.LENGTH_LONG).show(); if (parser.getEx().getErrorCode() > 0) return; } String outStr = null; if (cbPretty.isChecked()) { JSONWriter jw = new JSONWriter(); try { jo.writeJSONString(jw); } catch (IOException e) { e.printStackTrace(); } outStr = jw.toString(); } else outStr = jo.toJSONString(); EditText etOutput = (EditText) findViewById(R.id.etOutput); etOutput.setText(outStr); // tfOutputSize.setText(String.valueOf(outStr.length())); } catch (IOException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:cc.siara.csv_ml_demo.MultiLevelCSVSwingDemo.java
/** * Parses csv_ml from input box to JSON object and sets to output text box *//*w w w. ja va 2s .com*/ void toJSON() { try { JSONObject jo = parser.parseToJSO(new StringReader(taInput.getText()), false); String ex_str = parser.getEx().get_all_exceptions(); if (ex_str.length() > 0) { JOptionPane.showMessageDialog(null, ex_str); if (parser.getEx().getErrorCode() > 0) return; } String outStr; if (cbPretty.isSelected()) { JSONWriter jw = new JSONWriter(); try { jo.writeJSONString(jw); } catch (IOException e) { e.printStackTrace(); } outStr = jw.toString(); } else outStr = jo.toJSONString(); taOutput.setText(outStr); tfOutputSize.setText(String.valueOf(outStr.length())); taOutput.setCaretPosition(0); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); e.printStackTrace(); } }