Example usage for org.json JSONObject has

List of usage examples for org.json JSONObject has

Introduction

In this page you can find the example usage for org.json JSONObject has.

Prototype

public boolean has(String key) 

Source Link

Document

Determine if the JSONObject contains a specific key.

Usage

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a double array.
 * /* ww  w  .  jav  a 2s .com*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected double[] deserializeDoubleArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            double[] outArray = new double[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = array.getDouble(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize double array property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name from the specified json object into a double.
 * //from  www .j  av a2 s  . c  om
 * @param object the json object
 * @param name the property name
 * @return the deserialized double or <code>0.0d</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected double deserializeDouble(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            return object.getDouble(name);
        }

        return 0.0d;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize double property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a float array.
 * /*from  ww w . j  a v  a 2 s  . co  m*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected float[] deserializeFloatArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            float[] outArray = new float[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = (float) array.getDouble(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize float array property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name from the specified json object into a float.
 * /*from w  w  w.  j a v  a 2  s.co  m*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized float or <code>0.0f</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected float deserializeFloat(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            return (float) object.getDouble(name);
        }

        return 0.0f;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize float property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a integer array.
 * /*from  w ww  . ja v a 2s. c  o  m*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected int[] deserializeIntArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            int[] outArray = new int[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = array.getInt(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize integer array property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name from the specified json object into a integer.
 * /*www.j  a v  a  2s .co  m*/
 * @param object the json object to deserialize property from
 * @param name name of the property
 * @return the deserialized integer or <code>0</code> if property doesn't exist
 * @throws SerializerException uf unable to deserialize value
 */
protected int deserializeInt(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            return object.getInt(name);
        }

        return 0;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize int property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a long array.
 * //from w ww .  j ava 2s.co m
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected long[] deserializeLongArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            long[] outArray = new long[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = array.getLong(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize long array property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a long.
 * //from  w  ww .j a v  a2s .  c o m
 * @param object the json object
 * @param name the property name
 * @return the deserialized value or <code>0</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected long deserializeLong(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            return object.getLong(name);
        }

        return 0;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize long property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a short array.
 * //  w  w w .  ja  v a 2s.  c  o  m
 * @param object the json object
 * @param name the property name
 * @return the deserialized array or <code>null</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected short[] deserializeShortArray(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            JSONArray array = object.getJSONArray(name);
            short[] outArray = new short[array.length()];

            for (int i = 0; i < array.length(); i++) {
                outArray[i] = (short) array.getInt(i);
            }

            return outArray;
        }

        return null;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize short array property " + name, e);
    }
}

From source file:com.nginious.http.serialize.JsonDeserializer.java

/**
 * Deserializes property with the specified name in the specified json object into a short.
 * /*from   w  w w .  j  av a 2 s  .  co  m*/
 * @param object the json object
 * @param name the property name
 * @return the deserialized value or <code>0</code> if property doesn't exist
 * @throws SerializerException if unable to deserialize value
 */
protected short deserializeShort(JSONObject object, String name) throws SerializerException {
    try {
        if (object.has(name)) {
            return (short) object.getInt(name);
        }

        return 0;
    } catch (JSONException e) {
        throw new SerializerException("Can't deserialize short property " + name, e);
    }
}