JSON objects
From iRidium Mobile Wiki
DOWNLOAD: Example of a project
Description
In iRidiumScript you can create and edit JSON-objects.
JSON-object is the text format of data exchange based on and usually used with JavaScript.
Example of a JSON-object:
"firstName": "Peter",
"lastName": "Smirnoff",
"address": {
"streetAddress": "101 Central Street",
"city": "Saint Petersbug",
"postalCode": 101101
},
"phoneNumbers": [
"812 123-1234",
"916 123-4567"
]
In iRidiumScript you can use the following commands to work with JSON-objects:
- JSON.Parse(value); - instruction for converting a line into a JSON-object
- JSON.Stringify(value); - instruction for converting a JSON-object into a line
var text = '{"firstName": "Peter","lastName": "Smirnoff","address": {"streetAddress": "101 Central Street", "city": "Saint Petersburg", "postalCode": 101101},"phoneNumbers": ["812 123-1234","916 123-4567"]}'
IR.AddListener(IR.EVENT_START,0,function() //Event is activated at the application launch
{
IR.Log("text = "+text); //Output of the initial text in the log
var JSONObject = JSON.Parse(text); //Convert the initial text into a JSON-object
IR.Log("JSONObject = "+JSONObject.lastName); //Output the JSON-object in the log
var TextFromJSON = JSON.Stringify(JSONObject); //Convert the JSON-object into a text line
IR.Log("TextFromJSON = "+TextFromJSON); //Output of the received text line in the log
});