Java Code Examples for org.codehaus.jettison.json.JSONArray#getDouble()

The following examples show how to use org.codehaus.jettison.json.JSONArray#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GPOType.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index)
{
  Float val;

  try {
    val = (float)jo.getDouble(index);
  } catch (JSONException ex) {
    throw new IllegalArgumentException("The key " + field + " does not have a valid double value.", ex);
  }

  gpo.setFieldGeneric(field, val);
}
 
Example 2
Source File: GPOType.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index)
{
  Double val;

  try {
    val = jo.getDouble(index);
  } catch (JSONException ex) {
    throw new IllegalArgumentException("The key " + field + " does not have a valid double value.", ex);
  }

  gpo.setFieldGeneric(field, val);
}
 
Example 3
Source File: Extractor.java    From OSTMap with Apache License 2.0 4 votes vote down vote up
public static Double[] extractLocation(JSONObject obj) {
    Double longitude = 0.0;
    Double latitude = 0.0;
    try {
        if (!obj.isNull("coordinates")) {
            if (!obj.getJSONObject("coordinates").isNull("coordinates")) {
                JSONArray coords = obj.getJSONObject("coordinates").getJSONArray("coordinates");

                longitude = coords.getDouble(0);
                latitude = coords.getDouble(1);

            }
        } else {
            //System.out.println("In places");
            JSONArray places = obj.getJSONObject("place").getJSONObject("bounding_box").getJSONArray("coordinates").getJSONArray(0);

            if (places.length() > 2) {
                Double topLeftLong = places.getJSONArray(0).getDouble(0);
                Double topLeftLat = places.getJSONArray(0).getDouble(1);

                Double lowerLeftLong = places.getJSONArray(1).getDouble(0);
                Double lowerLeftLat = places.getJSONArray(1).getDouble(1);

                Double topRightLong = places.getJSONArray(2).getDouble(0);
                Double topRightLat = places.getJSONArray(2).getDouble(1);

                Double lowerRightLong = places.getJSONArray(3).getDouble(0);
                Double lowerRightLat = places.getJSONArray(3).getDouble(1);

                longitude = (topLeftLong + lowerLeftLong + topRightLong + lowerRightLong) / 4;
                latitude = (topLeftLat + lowerLeftLat + topRightLat + lowerRightLat) / 4;
            }
        }
        Double[] longLat = {longitude, latitude};
        return longLat;


    } catch (JSONException e) {
        System.err.println("No Correct JSON File");
        e.printStackTrace();
        return null;
    }

}