首页 > 文档 > parseJSONObject()获取JSONObject
2017
07-14

parseJSONObject()获取JSONObject

3-12.parseJSONObject()

Name(名称):

Examples(例子):

String data = “{ \”id\”: 0, \”species\”: \”Panthera leo\”, \”name\”: \”Lion\”}”;

 

void setup() {

JSONObject json = parseJSONObject(data);

if (json == null) {

println(“JSONObject could not be parsed”);

} else {

String species = json.getString(“species”);

println(species);

}

}

 

// Sketch prints:

// Panthera leo

Description(描述):Takes a String, parses its contents, and returns a JSONObject. If the String does not contain JSONObject data or cannot be parsed, a null value is returned.
获取字符串,解析其内容,并返回一个JSONObject。 如果String不包含JSONObject数据或无法解析,则返回空值。
parseJSONObject() 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 JSONObject using parseJSONObject(). Be sure to check if null is returned before performing operations on the new JSONObject in case the String content could not be parsed.
当动态拉动数据时,parseJSONObject()在第三方API方面是最有用的。 通常,API结果将保存到String,然后可以使用parseJSONObject()转换为结构化的JSONObject。 在新的JSONObject执行操作之前,请确保检查是否返回null,以防无法解析String内容。
If your data already exists as a JSON file in the data folder, it is simpler to use loadJSONObject().

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

Syntax(语法):parseJSONObject(input)

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

Returns(返回值):JSONObject

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

 


 



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

留下一个回复

你的email不会被公开。