首页 > 文档 > parseJSONArray()获取JSONArray
2017
07-14

parseJSONArray()获取JSONArray

3-11.parseJSONArray()

Name(名称):

Examples(例子):

String data = “[ \”Capra hircus\”, \”Panthera pardus\”, \”Equus zebra\” ]”;

 

void setup() {

JSONArray json = parseJSONArray(data);

if (json == null) {

println(“JSONArray could not be parsed”);

} else {

String species = json.getString(1);

println(species);

}

}

 

// Sketch prints:

// Panthera pardus

Description(描述):Takes a String, parses its contents, and returns a JSONArray. If the String does not contain JSONArray data or cannot be parsed, a null value is returned.

获取一个String,解析其内容,并返回一个JSONArray。 如果String不包含JSONArray数据或无法解析,则返回空值

parseJSONArray() is most useful when pulling data dynamically, such as from third-party APIs. Normally, API results would be saved to a String, and then can be converted to a structured JSONArray using parseJSONArray(). Be sure to check if null is returned before performing operations on the new JSONArray in case the String content could not be parsed.

当动态地拉动数据时,parseJSONArray()是最有用的,例如来自第三方API。 通常,API结果将保存到String,然后可以使用parseJSONArray()转换为结构化的JSONArray。 在新的JSONArray执行操作之前,请确保检查是否返回null,以防无法解析String内容。

If your data already exists as a JSON file in the data folder, it is simpler to use loadJSONArray().

如果您的数据已经作为数据文件夹中的JSON文件存在,那么使用loadJSONArray()就更简单了。

Syntax(语法):parseJSONArray(input)

Parameters (参数):input——String to parse as a JSONArray字符串解析为JSONArray

Returns(返回值):JSONArray

Related(相关函数):JSONObject
loadJSONObject()
saveJSONObject()



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

留下一个回复

你的email不会被公开。