當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing loadJSONObject()用法及代碼示例

Processing, loadJSONObject()用法介紹。

用法

  • loadJSONObject(filename)

參數

  • filename (String) 數據文件夾中的文件名或 URL

返回

  • JSONObject

說明

從數據文件夾或 URL 加載 JSON,並返回 JSONObject



Processing API 加載和保存的所有文件都使用 UTF-8 編碼。

例子

// 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": "Panthera leo",
   "name": "Lion"
  }
*/

JSONObject json;

void setup() {

  json = loadJSONObject("data.json");

  int id = json.getInt("id");
  String species = json.getString("species");
  String name = json.getString("name");

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

// Sketch prints:
// 0, Panthera leo, Lion

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 loadJSONObject()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。