/** * Get the string associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return A string value. * @throws JSONException * If there is no value for the index. */ public String getString(int index) throws JSONException { return get(index).toString(); }
/** * Get the int value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return The value. * @throws JSONException * If the key is not found or if the value cannot be converted to a * number. if the value cannot be converted to a number. */ public int getInt(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number) o).intValue() : (int) getDouble(index); }
sb.append('>'); do { e = ja.get(i); i += 1; if (e != null) {
/** * Get the string associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return A string value. * @throws JSONException * If there is no value for the index. */ public String getString(int index) throws JSONException { return get(index).toString(); }
/** * Get the long value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return The value. * @throws JSONException * If the key is not found or if the value cannot be converted to a * number. */ public long getLong(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number) o).longValue() : (long) getDouble(index); }
/** * Get the JSONArray associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return A JSONArray value. * @throws JSONException * If there is no value for the index. or if the value is not a * JSONArray */ public JSONArray getJSONArray(int index) throws JSONException { Object o = get(index); if (o instanceof JSONArray) { return (JSONArray) o; } throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); }
/** * Get the int value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return The value. * @throws JSONException * If the key is not found or if the value cannot be converted to a * number. if the value cannot be converted to a number. */ public int getInt(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number) o).intValue() : (int) getDouble(index); }
/** * Get the JSONObject associated with an index. * * @param index * subscript * @return A JSONObject value. * @throws JSONException * If there is no value for the index or if the value is not a * JSONObject */ public JSONObject getJSONObject(int index) throws JSONException { Object o = get(index); if (o instanceof JSONObject) { return (JSONObject) o; } throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); }
/** * Get the long value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return The value. * @throws JSONException * If the key is not found or if the value cannot be converted to a * number. */ public long getLong(int index) throws JSONException { Object o = get(index); return o instanceof Number ? ((Number) o).longValue() : (long) getDouble(index); }
/** * Get the boolean value associated with an index. The string values "true" * and "false" are converted to boolean. * * @param index * The index must be between 0 and length() - 1. * @return The truth. * @throws JSONException * If there is no value for the index or if the value is not * convertable to boolean. */ public boolean getBoolean(int index) throws JSONException { Object o = get(index); if (o.equals(Boolean.FALSE) || (o instanceof String && ((String) o).equalsIgnoreCase("false"))) { return false; } else if (o.equals(Boolean.TRUE) || (o instanceof String && ((String) o).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONArray[" + index + "] is not a Boolean."); }
/** * Get the JSONArray associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return A JSONArray value. * @throws JSONException * If there is no value for the index. or if the value is not a * JSONArray */ public JSONArray getJSONArray(int index) throws JSONException { Object o = get(index); if (o instanceof JSONArray) { return (JSONArray) o; } throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); }
/** * Get the JSONObject associated with an index. * * @param index * subscript * @return A JSONObject value. * @throws JSONException * If there is no value for the index or if the value is not a * JSONObject */ public JSONObject getJSONObject(int index) throws JSONException { Object o = get(index); if (o instanceof JSONObject) { return (JSONObject) o; } throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); }
/** * Get the double value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return The value. * @throws JSONException * If the key is not found or if the value cannot be converted to a * number. */ public double getDouble(int index) throws JSONException { Object o = get(index); try { return o instanceof Number ? ((Number) o).doubleValue() : Double.valueOf((String) o) .doubleValue(); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } }
/** * Get the double value associated with an index. * * @param index * The index must be between 0 and length() - 1. * @return The value. * @throws JSONException * If the key is not found or if the value cannot be converted to a * number. */ public double getDouble(int index) throws JSONException { Object o = get(index); try { return o instanceof Number ? ((Number) o).doubleValue() : Double.valueOf((String) o) .doubleValue(); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } }
/** * Get the boolean value associated with an index. The string values "true" * and "false" are converted to boolean. * * @param index * The index must be between 0 and length() - 1. * @return The truth. * @throws JSONException * If there is no value for the index or if the value is not * convertable to boolean. */ public boolean getBoolean(int index) throws JSONException { Object o = get(index); if (o.equals(Boolean.FALSE) || (o instanceof String && ((String) o).equalsIgnoreCase("false"))) { return false; } else if (o.equals(Boolean.TRUE) || (o instanceof String && ((String) o).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONArray[" + index + "] is not a Boolean."); }
len = ja.length(); for (i = 0; i < len; i += 1) { e = ja.get(i); if (e != null) { if (e instanceof String) {
@Override public List<IMetadata> search(String query, String authorityId) { ArrayList<IMetadata> ret = new ArrayList<IMetadata>(); try { JSONResource res = new Resty().json(getSearchURL(query)); JSONArray ares = res.array(); // JSONArray ares = (JSONArray) res.get("results"); for (int i = 0; i < ares.length(); i++) { JSONObject ores = (JSONObject) ares.get(i); if (ores != null) { Object rank = ores.get("rank"); if (!rankOK(rank)) continue; Metadata md = new Metadata(); md.put("ID", ores.get("speciesKey")); md.put("Label", ores.get("canonicalName")); ret.add(md); } } } catch (Exception e) { } return ret; }
/** * TODO: * * 1. use specific authority 2. use Java clients from GBIF 3. provide paging * * @param query * @return */ public List<IMetadata> searchGBIF(String query) { ArrayList<IMetadata> ret = new ArrayList<>(); try { JSONResource res = new Resty().json(getSearchURL(query)); JSONArray ares = res.array(); // JSONArray ares = (JSONArray) res.get("results"); for (int i = 0; i < ares.length(); i++) { JSONObject ores = (JSONObject) ares.get(i); if (ores != null) { Object rank = ores.get("rank"); if (!rankOK(rank)) continue; Metadata md = new Metadata(); md.put("ID", ores.get("speciesKey")); md.put("Label", ores.get("canonicalName")); ret.add(md); } } } catch (Exception e) { } return ret; }