Example usage for org.json JSONStringer toString

List of usage examples for org.json JSONStringer toString

Introduction

In this page you can find the example usage for org.json JSONStringer toString.

Prototype

public String toString() 

Source Link

Document

Return the JSON text.

Usage

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * Returns an array of information objects representing the set of all MIDI
 * devices available on the system.//from w  w  w.j av  a 2s  .c  o  m
 *
 * @return The array of information objects about all available MIDI
 *         devices.
 * @throws JSONException
 *             When JSON string could not be constructed.
 */
public String getMidiDeviceInfo() throws JSONException {
    final JSONStringer js = new JSONStringer();
    js.array();
    for (final Info info : MidiSystem.getMidiDeviceInfo()) {
        js.object();
        js.key("name").value(info.getName());
        js.key("description").value(info.getDescription());
        js.key("vendor").value(info.getVendor());
        js.key("version").value(info.getVersion());
        js.endObject();
    }
    js.endArray();
    return js.toString();
}

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * Returns all currently open receivers.
 *
 * @param deviceHandle/*from  w ww.  j  a  va 2  s. c  om*/
 *            The device handle.
 * @return All currently open receivers in form of a JSON-encoded string
 *         which describes an array of receiver handles.
 * @throws JSONException
 *             When JSON data could not be constructed.
 */
public String getReceivers(final int deviceHandle) throws JSONException {
    final MidiDevice device = resolveDeviceHandle(deviceHandle);
    final JSONStringer json = new JSONStringer();
    json.array();
    for (final Receiver receiver : device.getReceivers()) {
        json.value(System.identityHashCode(receiver));
    }
    json.endArray();
    return json.toString();
}

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * Returns all currently open transmitters.
 *
 * @param deviceHandle//  w w w . j a  v  a2  s. co  m
 *            The device handle.
 * @return All currently open transmitters in form of a JSON-encoded string
 *         which describes an array of transmitter handles.
 * @throws JSONException
 *             When JSON data could not be constructed.
 */
public String getTransmitters(final int deviceHandle) throws JSONException {
    final MidiDevice device = resolveDeviceHandle(deviceHandle);
    final JSONStringer json = new JSONStringer();
    json.array();
    for (final Transmitter transmitter : device.getTransmitters()) {
        json.value(System.identityHashCode(transmitter));
    }
    json.endArray();
    return json.toString();
}

From source file:de.ailis.midi4js.Midi4JS.java

/**
 * Returns the device info of the specified device.
 *
 * @param deviceHandle//from  w  w w .  j a  v  a2  s .  co m
 *            The device handle.
 * @return The device info as a JSON string.
 * @throws JSONException
 *             When JSON output fails.
 */
public String getMidiDeviceInfo(final int deviceHandle) throws JSONException {
    final MidiDevice device = resolveDeviceHandle(deviceHandle);
    final JSONStringer json = new JSONStringer();
    deviceInfo(json, device.getDeviceInfo());
    return json.toString();
}