Reference+
Class Name
JSONObject
Description
A 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.
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" // }
Methods
getString()
Gets the String value associated with the specified keygetInt()
Gets the int value associated with the specified keygetFloat()
Gets the float value associated with a keygetBoolean()
Gets the boolean value associated with the specified keygetJSONArray()
Retrieves the JSONArray with the associated keygetJSONObject()
Given a key value, retrieves the associated JSONObjectisNull()
Determines if the value associated with the key is null, that is has no defined value (false) or if it has a value (true)setString()
Inserts a new key/String pair into the JSONObjectsetInt()
Inserts a new key/int pair into the JSONObjectsetFloat()
Put a key/float pair in the JSONObjectsetBoolean()
Put a key/boolean pair in the JSONObjectsetJSONObject()
Sets the value of the JSONObject with the associated keysetJSONArray()
Sets the value of the JSONArray with the associated key
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.