Graphics Programs Reference
In-Depth Information
For the More Curious: JSON Data
JSON is a data interchange format - a way of describing data so it can be transferred to an-
other system easily. It has a really concise and easy to understand syntax. First, let's think
about why we need to transfer data. An application has some model objects that represent
things - like items in an RSS feed. It would make sense that this application would want to
share these items with another device.
However, let's say that other device is an Android phone (and, in our imaginary world, let's
pretend this Android phone's battery is not drained dry). We can't just package up an
Objective-C RSSItem object and send it to the Android device. We need an agreed-upon
format that both systems understand. Both Java (the language Android is programmed in)
and Objective-C have a concept of objects, and both platforms have the ideas of arrays,
strings, and numbers. JSON reduces data down to this very pure format of objects, arrays,
strings and numbers, so the two platforms can share data.
In JSON, there is a syntax for each of these types. Objects are represented by curly brack-
ets. Inside an object can be a number of members, each of which is a string, number, array,
or another object. Each member has a name. Here is an example of an object that has two
members, one a string, the other a number.
{
"name":"Joe Conway",
"age":28
}
When this JSON object is parsed by NSJSONSerialization , it is turned into an
NSDictionary . That dictionary has two key-value pairs: name which is Joe Conway
and age which is 28 . On another platform, this object would be represented in some other
way, but on iOS, it is a dictionary because that is what makes the most sense. Additionally,
all keys within the dictionary will be instances of NSString . The string value is also an
instance of NSString , and the number value is an instance of NSNumber .
An array is described by using square brackets in JSON. It can contain objects, strings,
numbers, and more arrays. Here is an example of an array that contains two objects:
[
{
"name":"Joe Conway",
"age":28
},
Search WWH ::




Custom Search