Codota Logo
JSONArray
Code IndexAdd Codota to your IDE (free)

How to use
JSONArray
in
us.monoid.json

Best Java code snippets using us.monoid.json.JSONArray (Showing top 20 results out of 315)

  • Common ways to obtain JSONArray
private void myMethod () {
JSONArray j =
  • Codota IconJSONObject jSONObject;String str;jSONObject.getJSONArray(str)
  • Codota IconJSONResource jSONResource;jSONResource.array()
  • Smart code suggestions by Codota
}
origin: us.monoid.web/resty

/**
 * Produce a JSONArray containing the names of the elements of this
 * JSONObject.
 * 
 * @return A JSONArray containing the key strings, or null if the JSONObject
 *         is empty.
 */
public JSONArray names() {
  JSONArray ja = new JSONArray();
  Iterator<String> keys = keys();
  while (keys.hasNext()) {
    ja.put(keys.next());
  }
  return ja.length() == 0 ? null : ja;
}
origin: us.monoid.web/resty

/**
 * 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();
}
origin: org.ihtsdo.otf.common/otf-common

private JSONObject getLatestClassificationObjectOnBranch(String branchPath) throws RestClientException {
  final String classificationsUrl = urlHelper.getClassificationsUrl(branchPath);
  try {
    final JSONArray items = getItems(classificationsUrl);
    if (items != null && items.length() > 0) {
      return items.getJSONObject(items.length() - 1);
    }
    return null;
  } catch (Exception e) {
    throw new RestClientException("Failed to retrieve list of classifications.", e);
  }
}
origin: beders/Resty

/**
 * Put a value in the JSONArray, where the value will be a JSONArray which is
 * produced from a Collection.
 * 
 * @param value
 *          A Collection value.
 * @return this.
 */
public JSONArray put(Collection<?> value) {
  put(new JSONArray(value));
  return this;
}
origin: beders/Resty

/**
 * 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);
}
origin: beders/Resty

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.
 * 
 * @param names
 *          A JSONArray containing a list of key strings. This determines the
 *          sequence of the values in the result.
 * @return A JSONArray of values.
 * @throws JSONException
 *           If any of the values are non-finite numbers.
 */
public JSONArray toJSONArray(JSONArray names) throws JSONException {
  if (names == null || names.length() == 0) {
    return null;
  }
  JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1) {
    ja.put(this.opt(names.getString(i)));
  }
  return ja;
}
origin: us.monoid.web/resty

if (o instanceof JSONArray) {
 JSONArray array = JSONArray.class.cast(o);
 return array.get(index);
 } else {
 return null;
   for (int i = 0, len = array.length(); i < len; i++) {
    Object item = array.get(i);
    boolean test = at(0).test(item);
        if (test) {
         result = item; // evaluation can continue on this item
                                break;
  if (item instanceof JSONObject)
          JSONObject obj = (JSONObject)item;
          if (obj.has(this.value.toString()))
origin: beders/Resty

tagName = ja.getString(0);
XML.noSpace(tagName);
tagName = XML.escape(tagName);
sb.append(tagName);
e = ja.opt(1);
if (e instanceof JSONObject) {
  i = 2;
length = ja.length();
if (i >= length) {
  sb.append('/');
  sb.append('>');
  do {
    e = ja.get(i);
    i += 1;
    if (e != null) {
origin: beders/Resty

/**
 * Get the optional object value associated with an index.
 * 
 * @param index
 *          The index must be between 0 and length() - 1.
 * @return An object value, or null if there is no object at that index.
 */
public Object opt(int index) {
  return (index < 0 || index >= length()) ? null : this.myArrayList.get(index);
}
origin: beders/Resty

/**
 * Produce a JSONObject by combining a JSONArray of names with the values of
 * this JSONArray.
 * 
 * @param names
 *          A JSONArray containing a list of key strings. These will be paired
 *          with the values.
 * @return A JSONObject, or null if there are no names or if this JSONArray
 *         has no values.
 * @throws JSONException
 *           If any of the names are null.
 */
public JSONObject toJSONObject(JSONArray names) throws JSONException {
  if (names == null || names.length() == 0 || length() == 0) {
    return null;
  }
  JSONObject jo = new JSONObject();
  for (int i = 0; i < names.length(); i += 1) {
    jo.put(names.getString(i), this.opt(i));
  }
  return jo;
}
origin: beders/Resty

    if (v instanceof JSONArray) {
      ja = (JSONArray)v;
      len = ja.length();
      for (i = 0; i < len; i += 1) {
        if (i > 0) {
          b.append('\n');
        b.append(escape(ja.get(i).toString()));
    len = ja.length();
    for (i = 0; i < len; i += 1) {
      v = ja.get(i);
      if (v instanceof JSONArray) {
        b.append('<');
len = ja.length();
for (i = 0; i < len; ++i) {
  v = ja.opt(i);
  b.append(toString(v, (tagName == null) ? "array" : tagName));
origin: org.ihtsdo.otf.common/otf-common

public List<String> retrieveValidationStatuses(List<String> branchPaths) throws Exception {
  StringBuilder url = new StringBuilder(orchestrationUrl + VALIDATIONS_ENDPOINT + "/bulk/latest/statuses");
  url.append("?paths=");
  boolean first = true;
  for (String branchPath : branchPaths) {
    if (!first) {
      url.append(",");
    } else {
      first = false;
    }
    url.append(branchPath);
  }
  final JSONResource resource = getResource(url.toString());
  if (resource == null) {
    return null;
  }
  final JSONArray array = resource.array();
  List<String> statuses = new ArrayList<>();
  for (int a = 0; a < array.length(); a++) {
    final String string = array.getString(a);
    statuses.add(!string.equals("null") ? string : null);
  }
  return statuses;
}
origin: beders/Resty

a = new JSONArray(s);
System.out.println(a.toString());
System.out.println("");
System.out.println(a.toString(4));
System.out.println(JSONML.toString(a));
System.out.println();
System.out.println(a.toString(4));
System.out.println(JSONML.toString(a));
System.out.println();
System.out.println(new JSONArray(jj.toString()).toString(4));
JSONArray ja = new JSONArray(ar);
System.out.println(ja.toString());
j.put("String", "98.6");
j.put("JSONObject", new JSONObject());
j.put("JSONArray", new JSONArray());
j.put("int", 57);
j.put("double", 123456789012345678901234567890.);
j.put("\\u2029", "\u2029");
a = j.getJSONArray("foo");
a.put(666);
a.put(2001.99);
a.put("so \"fine\".");
a.put("so <fine>.");
origin: org.ihtsdo.otf.common/otf-common

boolean equivalentConceptsFound = !(items == null || items.length() == 0);
results.setEquivalentConceptsFound(equivalentConceptsFound);
if (equivalentConceptsFound) {
  results.setEquivalentConceptsJson(toPrettyJson(items.toString()));
origin: beders/Resty

  /**
   * Produce a comma delimited text from a JSONArray of JSONObjects using
   * a provided list of names. The list of names is not included in the
   * output.
   * @param names A JSONArray of strings.
   * @param ja A JSONArray of JSONObjects.
   * @return A comma delimited text.
   * @throws JSONException
   */
  public static String toString(JSONArray names, JSONArray ja)
      throws JSONException {
    if (names == null || names.length() == 0) {
      return null;
    }
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < ja.length(); i += 1) {
      JSONObject jo = ja.optJSONObject(i);
      if (jo != null) {
        sb.append(rowToString(jo.toJSONArray(names)));
      }
    }
    return sb.toString();
  }
}
origin: beders/Resty

  throw new JSONException("JSONArray[" + index + "] not found.");
if (index < length()) {
  this.myArrayList.set(index, value);
} else {
  while (index != length()) {
    put(JSONObject.NULL);
  put(value);
origin: beders/Resty

for (int i = 0; i < ja.length(); i += 1) {
  if (i > 0) {
    sb.append(',');
  Object o = ja.opt(i);
  if (o != null) {
    String s = o.toString();
origin: beders/Resty

try {
  boolean b = false;
  int len = length();
      ((JSONObject) v).write(writer);
    } else if (v instanceof JSONArray) {
      ((JSONArray) v).write(writer);
    } else {
      writer.write(JSONObject.valueToString(v));
origin: beders/Resty

return ((JSONArray) value).toString(indentFactor, indent);
return new JSONArray((Collection<?>) value).toString(indentFactor, indent);
return new JSONArray(value).toString(indentFactor, indent);
origin: us.monoid.web/resty

/**
 * Make a prettyprinted JSON text of this JSONArray. Warning: This method
 * assumes that the data structure is acyclical.
 * 
 * @param indentFactor
 *          The number of spaces to add to each level of indentation.
 * @return a printable, displayable, transmittable representation of the
 *         object, beginning with <code>[</code>&nbsp;<small>(left
 *         bracket)</small> and ending with <code>]</code>&nbsp;<small>(right
 *         bracket)</small>.
 * @throws JSONException
 */
public String toString(int indentFactor) throws JSONException {
  return toString(indentFactor, 0);
}
us.monoid.jsonJSONArray

Javadoc

A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the values. The internal form is an object having get and opt methods for accessing the values by index, and put methods for adding or replacing values. The values can be any of these types: Boolean, JSONArray, JSONObject, Number, String, or the JSONObject.NULL object.

The constructor can convert a JSON text into a Java object. The toString method converts to JSON text.

A get method returns a value if one can be found, and throws an exception if one cannot be found. An opt method returns a default value instead of throwing an exception, and so is useful for obtaining optional values.

The generic get() and opt() methods return an object which you can cast or query for type. There are also typed get and opt methods that do type checking and type coercion for you.

The texts produced by the toString methods strictly conform to JSON syntax rules. The constructors are more forgiving in the texts they will accept:

  • An extra , (comma) may appear just before the closing bracket.
  • The null value will be inserted when there is ,  (comma) elision.
  • Strings may be quoted with ' (single quote).
  • Strings do not need to be quoted at all if they do not begin with a quote or single quote, and if they do not contain leading or trailing spaces, and if they do not contain any of these characters: { } [ ] / \ : , = ; # and if they do not look like numbers and if they are not the reserved words true, false, or null.
  • Values can be separated by ; (semicolon) as well as by , (comma).
  • Numbers may have the 0x- (hex) prefix.

Most used methods

  • length
    Get the number of elements in the JSONArray, included nulls.
  • get
    Get the object value associated with an index.
  • getJSONObject
    Get the JSONObject associated with an index.
  • getString
    Get the string associated with an index.
  • toString
    Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structu
  • <init>
    Construct a JSONArray from a JSONTokener.
  • getBoolean
    Get the boolean value associated with an index. The string values "true" and "false" are converted t
  • getDouble
    Get the double value associated with an index.
  • getInt
    Get the int value associated with an index.
  • getLong
    Get the long value associated with an index.
  • join
    Make a string from the contents of this JSONArray. Theseparator string is inserted between each elem
  • opt
    Get the optional object value associated with an index.
  • join,
  • opt,
  • optBoolean,
  • optDouble,
  • optInt,
  • optJSONObject,
  • optLong,
  • optString,
  • put,
  • toJSONObject

Popular in Java

  • Finding current android device location
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSystemService (Context)
  • getContentResolver (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now