JSON
JavaScript Object Notation (JSON) is a human readable data interchange format. It's very flexible, fast, and easy to use and understand and is included in the core of Titanium. It's used throughout the examples on the Appcelerator website, and it should also be used throughout your code. You are likely to use it whenever you pass data around in Titanium, including function parameters, as well as variables and a host of other areas.
I will highlight the flexibility it provides with an example. Should you want a reference guide then go to http://json.org/.
JSON is created using the {}
constructor. It consists of a set of name/value pairs. It's best explained using an example. Here is a list of sample JSON definitions in a format that can be used in Titanium:
JSON |
Description |
---|---|
var myJSON = {};
|
Empty JSON variable |
var myJSON = {aNum : 1};
|
Number attribute |
var myJSON = { Array : ['elem1', 'elem2', 'elem3']};
|
An array within JSON |
setWindowProperties = ({top : 0, bottom: 0, backgroundColor... |