loadJSONArray()

本参考资料用于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.

名称

loadJSONArray()

示例
 // The following short JSON file called "data.json" is parsed  // in the code below. It must be in the project's "data" folder. // // [ //{ //   "id": 0, //   "species": "Capra hircus", //   "name": "Goat" //
  }, //{ //   "id": 1, //   "species": "Panthera pardus", //   "name": "Leopard" //
  }, //{ //   "id": 2, //   "species": "Equus zebra", //   "name": "Zebra" //
  } // ]  JSONArray values;



void setup()
{  
 values = loadJSONArray("data.json");



for (int i = 0;

i < values.size();

i++)
{
    JSONObject animal = values.getJSONObject(i);




int id = animal.getInt("id");


String species = animal.getString("species");


String name = animal.getString("name");



println(id + ", " + species + ", " + name);


   }
  }  // Sketch prints: // 0, Capra hircus, Goat // 1, Panthera pardus, Leopard // 2, Equus zebra, Zebra 
描述 Loads an array of JSON objects from the data folder or a URL, and returns a JSONArray. Per standard JSON syntax, the array must be enclosed in a pair of hard brackets [], and each object within the array must be separated by a comma.

All files loaded and saved by the Processing API use UTF-8 encoding.

语法
loadJSONArray(filename) loadJSONArray(file)
参数
filename String: name of a file in the data folder or a URL
返回值 JSONArray
相关 JSONArray
loadJSONObject()
saveJSONObject()
saveJSONArray()

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

loadJSONArray()