首页 > 文档 > JSONObject JSON对象
2017
07-19

JSONObject JSON对象

Name

JSONObject JSON对象

Examples

JSONObject json;

 

void setup() {

 

json = new JSONObject();

 

json.setInt(“id”, 0);

json.setString(“species”, “Panthera leo”);

json.setString(“name”, “Lion”);

 

saveJSONObject(json, “data/new.json”);

}

 

// Sketch saves the following to a file called “new.json”:

// {

// “id”: 0,

// “species”: “Panthera leo”,

// “name”: “Lion”

// }

Description

JSONObject stores JSON data with multiple name/value pairs. Values can be numeric, Strings, booleans, other JSONObjects or JSONArrays, or null. JSONObject and JSONArray objects are quite similar and share most of the same methods; the primary difference is that the latter stores an array of JSON objects, while the former represents a single JSON object.

JSON can be generated from scratch, dynamically, or using data from an existing file. JSON can also be output and saved to disk, as in the example above.

JSONObject 存储具有多个名称/值对的 json 数据。数值可以是数字、字符串、布尔值、其他 JSONObjects JSONArrays nullJSONObject JSONArray 对象非常相似, 并且共享大多数相同的方法;主要区别在于后者存储了一个 json 对象数组, 而前者则表示一个 json 对象。

 

可以从头开始、动态地或使用现有文件中的数据生成 jsonjson 也可以输出并保存到磁盘上, 如上面的示例中所示。

Methods

getString()

Gets the string value associated with a key

获取与键关联的字符串值

getInt()

Gets the int value associated with a key

获取与键关联的 int

getFloat()

Gets the float value associated with a key

获取与键关联的浮点值

getBoolean()

Gets the boolean value associated with a key

获取与键关联的布尔值

getJSONArray()

Gets the JSONArray value associated with a key

获取与键关联的 JSONArray

getJSONObject()

Gets the JSONObject value associated with a key

获取与键关联的 JSONObject

isNull()

Determine if the value associated with the key is null or if there is no value.

确定与该键关联的值是 null 还是没有值。

setString()

Put a key/String pair in the JSONObject

jsonobject 中放置一个键/字符串对

setInt()

Put a key/int pair in the JSONObject

jsonobject 中放置一个键/int

setFloat()

Put a key/float pair in the JSONObject

jsonobject 中放置一个键/浮点对

setBoolean()

Put a key/boolean pair in the JSONObject

jsonobject 中放置一个键/布尔对

setJSONObject()

Sets the JSONObject value associated with a key

设置与键关联的 JSONObject

setJSONArray()

Sets the JSONArray value associated with a key

设置与键关联的 JSONObject

   

Related

JSONArray
loadJSONObject()
loadJSONArray()
saveJSONObject()
saveJSONArray()



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

留下一个回复

你的email不会被公开。