Example usage for org.json.extension JSONConstructor value

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

Introduction

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

Prototype

JSONConstructor value(Object value) throws JSONException;

Source Link

Document

Writes an Object value.

Usage

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

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

    json.object();/*from www. j  ava  2s  . co 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();
}