首页 > 文档 > saveJSONArray()保存JSON数组
2017
08-02

saveJSONArray()保存JSON数组

Name

saveJSONArray()保存JSON数组

   

Examples

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”

// }

// ]

Description

Writes the contents of a JSONArray object to a file. By default, this file is saved to the sketch’s folder. This folder is opened by selecting “Show Sketch Folder” from the “Sketch” menu.

Alternatively, the file can be saved to any location on the computer by using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows).

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

JSONArray 对象的内容写入文件。默认情况下, 此文件保存到草绘的文件夹中。通过从草绘菜单中选择显示草图文件夹打开此文件夹。

 

或者, 该文件可以通过使用绝对路径 ( unix linux 上启动的东西, windows 上的驱动器号) 保存到计算机上的任何位置。

 

处理 api 加载和保存的所有文件都使用 UTF-8 编码。

Syntax

saveJSONArray(json, filename)

saveJSONArray(json, filename, options)

Parameters

json

JSONArray: the JSONArray to save

需要保存的JSON数组

filename

String: the name of the file to save to

需要保存的文件名

options

String: “compact” and “indent=N”, replace N with the number of spaces

字符串: “紧凑缩进 = n”, 替换 n 与空格数

Returns

boolean

Related

JSONObject
JSONArray
loadJSONObject()
loadJSONArray()
saveJSONObject()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。