Example usage for org.json.extension JSONConstructor key

List of usage examples for org.json.extension JSONConstructor key

Introduction

In this page you can find the example usage for org.json.extension JSONConstructor key.

Prototype

JSONConstructor key(String key) throws JSONException;

Source Link

Document

Writes a key.

Usage

From source file:de.cosmocode.palava.legacy.UpdateResult.java

@Override
public void encodeJSON(JSONConstructor json) throws JSONException {

    json.object();/*from  w  w  w.  j  a v a 2 s .c o  m*/
    if (errors == null && result == null && exception == null) {
        json.key("status").value("success");
    } else {
        json.key("status").value(isError() ? "error" : "success");
        if (errors != null)
            json.key("errors").value(errors);
        if (exception != null)
            json.key("exception").value(exception.toString());
        if (result != null) {
            json.key("result");
            if (result instanceof JSONEncoder) {
                final boolean objects = result instanceof NoObjectContext;
                if (objects)
                    json.object();
                ((JSONEncoder) result).encodeJSON(json);
                if (objects)
                    json.endObject();
            } else
                json.value(result);
        }
    }

    json.endObject();
}