Example usage for org.json.prettyprint JsonWriter formatJson

List of usage examples for org.json.prettyprint JsonWriter formatJson

Introduction

In this page you can find the example usage for org.json.prettyprint JsonWriter formatJson.

Prototype

public static String formatJson(String json) throws IOException 

Source Link

Document

Format the passed in JSON string in a nice, human readable format.

Usage

From source file:org.planetcrypto.bitcoin.PlanetCryptoBitcoinUI.java

private void CustomCommandSubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomCommandSubmitButtonActionPerformed
    String command = CustomCommandEntryTextField.getText();
    String miner = MinerSelectionBox.getSelectedItem().toString();
    Boolean json = CustomCommandJsonCheckBox.isSelected();
    if (command.equals("")) {
        JOptionPane.showMessageDialog(null, "Please enter a command.", "ERROR: NO COMMAND",
                JOptionPane.WARNING_MESSAGE);
    } else {/*ww w  .  j ava2s  .c o m*/
        for (int i = 0; i < existing_miners.size(); i++) {
            if (existing_miners.get(i).get("name").equals(miner)) {
                //System.out.println("Found compatible miner");
                String response = api_Commands.parseArgs(existing_miners.get(i).get("ip"),
                        existing_miners.get(i).get("port"), command, json);
                if (!json) {
                    try {
                        response = api_Commands.prettyPrint(response);
                        CustomCommandOutputTextArea.setText(response);
                        return;
                    } catch (IOException ex) {
                        Logger.getLogger(PlanetCryptoBitcoinUI.class.getName()).log(Level.SEVERE, null, ex);
                        CustomCommandOutputTextArea.setText("Error");
                        return;
                    }
                } else {
                    try {
                        String niceJSON = JsonWriter.formatJson(response);
                        CustomCommandOutputTextArea.setLineWrap(true);
                        CustomCommandOutputTextArea
                                .setText("Command: " + command + "\n" + "Response: \n" + niceJSON);
                        CustomCommandEntryTextField.setText("");
                        CustomCommandJsonCheckBox.setSelected(false);
                    } catch (IOException ex) {
                        Logger.getLogger(PlanetCryptoBitcoinUI.class.getName()).log(Level.SEVERE, null, ex);
                        CustomCommandOutputTextArea.setText("Command: " + command + "\nResponse: Error \n");
                        CustomCommandEntryTextField.setText("");
                        CustomCommandJsonCheckBox.setSelected(false);
                    }
                }
            }
        }
    }
}