JSONArray

本参考资料用于Processing 3.0+。 如果你使用的是前一版本,请在使用软件帮助菜单内的参考资料。. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

名称

JSONArray

示例
 String[] species ={ "Capra hircus", "Panthera pardus", "Equus zebra"
  };

String[] names ={ "Goat", "Leopard", "Zebra"
  };

 JSONArray values;



void setup()
{  
 values = new JSONArray();



for (int i = 0;

i < species.length;

i++)
{
JSONObject animal = new JSONObject();



animal.setInt("id", i);


animal.setString("species", species[i]);


animal.setString("name", names[i]);



values.setJSONObject(i, animal);


  }    saveJSONArray(values, "data/new.json");


  }  // Sketch saves the following to a file called "new.json": // [ //{ //   "id": 0, //   "species": "Capra hircus", //   "name": "Goat" //
  }, //{ //   "id": 1, //   "species": "Panthera pardus", //   "name": "Leopard" //
  }, //{ //   "id": 2, //   "species": "Equus zebra", //   "name": "Zebra" //
  } // ] 
描述 A JSONArray stores an array of JSON objects. JSONArrays can be generated from scratch, dynamically, or using data from an existing file. JSON can also be output and saved to disk, as in the example above.
Methods
getString() Gets the String value associated with an index
getInt() Gets the
int value associated with an index
getFloat() Gets thefloat value associated with an index
getBoolean() Gets the boolean value associated with an index
getJSONArray() Gets the JSONArray associated with an index value
getJSONObject() Gets the JSONObject associated with an index value
getStringArray() Gets the entire array as an array of Strings
getIntArray() Gets the entire array as array of ints
append() Appends a value, increasing the array's length by one
setString() Put a String value in the JSONArray
setInt() Put an
int value in the JSONArray
setFloat() Put afloat value in the JSONArray
setBoolean() Put a boolean value in the JSONArray
setJSONArray() Sets the JSONArray value associated with an index value
setJSONObject() Sets the JSONObject value associated with an index value
size() Gets the number of elements in the JSONArray
isNull() Determine if the value is null.
remove() Removes an element
Constructor
JSONArray() 
相关 JSONObject
loadJSONObject()
loadJSONArray()
saveJSONObject()
saveJSONArray()

Updated on October 2, 2018 05:02:12pm EDT

JSONArray