Example usage for com.google.gwt.json.client JSONException JSONException

List of usage examples for com.google.gwt.json.client JSONException JSONException

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONException JSONException.

Prototype

public JSONException(String message, Throwable cause) 

Source Link

Document

Constructs a new JSONException with the specified message and cause.

Usage

From source file:com.ponysdk.core.terminal.model.ReaderBuffer.java

License:Apache License

private JSONObject getJson(final int msgSize) {
    final String s = getStringUTF8(msgSize);
    try {/*from  www . j a v a2s  .c  om*/
        return s != null ? JSONParser.parseStrict(s).isObject() : null;
    } catch (final JSONException e) {
        throw new JSONException(e.getMessage() + " : " + s, e);
    }
}

From source file:org.geomajas.gwt2.client.service.JsonService.java

License:Open Source License

/**
 * Get a date value from a {@link JSONObject}.
 * /*ww  w. j  a v a 2  s  .  co m*/
 * @param jsonObject The object to get the key value from.
 * @param key The name of the key to search the value for.
 * @return Returns the value for the key in the object or null.
 * @throws JSONException Thrown in case the key could not be found in the JSON object, or if the date could not be
 *         parsed correctly.
 */
public static Date getDateValue(JSONObject jsonObject, String key) throws JSONException {
    checkArguments(jsonObject, key);
    JSONValue value = jsonObject.get(key);
    if (value != null && value.isString() != null) {
        String dateString = getStringValue(jsonObject, key);
        if (dateString.charAt(0) == '"') {
            dateString = dateString.substring(1);
        }
        if (dateString.endsWith("\"")) {
            dateString = dateString.substring(0, dateString.length() - 1);
        }
        try {
            return DEFAULT_DATEFORMAT.parse(dateString);
        } catch (Exception e) {
            try {
                long millis = Long.parseLong(dateString);
                return new Date(millis);
            } catch (Exception e2) {
                throw new JSONException("Could not parse the date for key '" + key + "'", e);
            }
        }
    }
    return null;
}