Search in sources :

Example 11 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class JSONWriter method key.

/**
     * Append a key. The key will be associated with the next value. In an
     * object, every value must be preceded by a key.
     * @param s A key string.
     * @return this
     * @throws JSONException If the key is out of place. For example, keys
     *  do not belong in arrays or if the key is null.
     */
public JSONWriter key(String s) throws JSONException {
    if (s == null) {
        throw new JSONException("Null key.");
    }
    if (this.mode == 'k') {
        try {
            if (this.comma) {
                this.writer.write(',');
            }
            this.writer.write(JSONObject.quote(s));
            this.writer.write(':');
            this.comma = false;
            this.mode = 'o';
            return this;
        } catch (IOException e) {
            throw new JSONException(e);
        }
    }
    throw new JSONException("Misplaced key.");
}
Also used : JSONException(com.openmeap.thirdparty.org.json.me.JSONException) IOException(java.io.IOException)

Example 12 with JSONException

use of com.openmeap.thirdparty.org.json.me.JSONException in project OpenMEAP by OpenMEAP.

the class JSONWriter method end.

/**
     * End something.
     * @param m Mode
     * @param c Closing character
     * @return this
     * @throws JSONException If unbalanced.
     */
private JSONWriter end(char m, char c) throws JSONException {
    if (this.mode != m) {
        throw new JSONException(m == 'o' ? "Misplaced endObject." : "Misplaced endArray.");
    }
    this.pop(m);
    try {
        this.writer.write(c);
    } catch (IOException e) {
        throw new JSONException(e);
    }
    this.comma = true;
    return this;
}
Also used : JSONException(com.openmeap.thirdparty.org.json.me.JSONException) IOException(java.io.IOException)

Aggregations

JSONException (com.openmeap.thirdparty.org.json.me.JSONException)12 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)10 IOException (java.io.IOException)6 JSONObjectBuilder (com.openmeap.json.JSONObjectBuilder)4 JSONArray (com.openmeap.thirdparty.org.json.me.JSONArray)4 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)3 Enumeration (java.util.Enumeration)3 Hashtable (java.util.Hashtable)3 HasJSONProperties (com.openmeap.json.HasJSONProperties)2 Result (com.openmeap.protocol.dto.Result)2 Vector (java.util.Vector)2 ClusterNodeRequest (com.openmeap.cluster.dto.ClusterNodeRequest)1 HttpRequestException (com.openmeap.http.HttpRequestException)1 HttpResponse (com.openmeap.http.HttpResponse)1 Enum (com.openmeap.json.Enum)1 WebServiceException (com.openmeap.protocol.WebServiceException)1 ConnectionOpenResponse (com.openmeap.protocol.dto.ConnectionOpenResponse)1 Error (com.openmeap.protocol.dto.Error)1 UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)1 JsError (com.openmeap.protocol.json.JsError)1