One of formats of data that Spry accepts is JSON. This document will present an overview of setting up JSON for use with Spry. It will have tips and tricks for generating and using JSON for Spry.
What is JSON?
JSON stands for JavaScript Object Notation. This is a lightweight, flexible yet strict method of storing and transmitting data. Flexible in that the user can create the format and names in any way they please; strict in the sense that JSON has a strict set of rules for structure.
Basic JSON code looks like this:
{
"firstName": "Jason",
"lastName": "Jones",
"address": {
"city": "San Francisco, CA",
"zip": 94121,
"address": "444 Columbus Ave"
},
"email": [
"jason@sf.com",
"sjones@adobe.com"
]
}
Let's break this down. A JavaScript object is a series of name/value pairs, written in a structured way. The basic structure is:
{name:value,name:value,name:value}
JSON supports the common data types listed below. Each has a set of rules for structure.
Boolean:"active":true
To send a false, send the word false:
"active":falseString:
"address": "444 Columbus Ave"Number:
"zip": 94121
Negative integers:
total points": -123
Floats:
"length":122.2344
Scientific notation:
"atoms per mole":-6.023e+23Array:
"values":[ 1, false, "test", [ 2, 3 ], { "test": 1 } ]
In the example above describes an array of 5 elements which include a number, boolean, string, array, and object.
Object:{ "count": 2, "results": [ 2, 3 ] }The example above describes an object with two properties on it, the "count" and "results" property. The "count" property has an integer value of 2, and the "results" value is an array.
Null:
In JavaScript, null is a pre-defined object. To send a null in JSON notation, you simply send the word null:
"email":null
http://www.dustindiaz.com/json-for-the-masses/
Copyright © 2007. Adobe Systems Incorporated.
All rights reserved.