JSON: JavaScript
Object Notation
A Great Implementation in HTML5 Game Development.
If you are a game developer then JSON is a very important
name in your kitty. JSON basically originated from the JavaScript. It is
represented with the two primary data structures i.e. Order List (Array) and
Objects pairs. JSON is a light-weight text oriented data-interchange format. It
is easy to implement as compare to XML. It is widely use format over the WWW.
JSON is language independent and its data structure, array
and objects are universality accepted. These structures are supported in some
way by most of the modern programming languages like Python, Perl, ASP, ABAP,
C, C++, C#, Lisp, COBOL, Ruby, Java, PL/SQL, Objective C, and many more.
Basics of JSON:
1.
Object: In this values are separated by
comma (,). Property of these objects can be accessed by its object name
followed by property name or by using
array.
Example:
myObj1 = { //Object myObj1 Created
"first": "Raj",
"last": "Singh", //Values separated
"age": 29, //by comma (,)
"sex": "M",
"salary": 30000,
"favourites": { //Object nested with object
"color": "grey",
"sport": "cricket",
}
"passion": [ "Music", "Biking" ]
//Object nested with object
}
Access these values:
·
myObj1.last
à Singh (Output)
·
myObj1[“first”]
à Raj (Output)
·
myObj1.favourites.sport
à cricket (Output)
·
myObj1[“favourites”][“sport”]
à cricket (Output)
·
myObj1[“passion”][0]
à Music (Output)
·
myObj1.
passion [0] Ã Music (Output)
2. Array : Elements of the array are of types (number, Boolean or
null, String).
Example:
myArray1 = [“Raj",
32, music, null] // Array
created
myArray2 = [
{"name": "Vijay", "age": 26},
{“name": "Sneha", "age": 25} //Array with objects
]
Access these values
·
myArray1
[2] Ã music (Output)
·
myArray2
[1].name à Sneha (Output)
3. Datatypes used in JSON Implementation
·
Number
Declaration:
var myNum1 = 123.456
Definition: Double-precision
floating-point format.
·
Stringvar
Declaration:
myString1="abcde##132jhdff"
Definition: Series of characters (letters, numbers, or symbols); double-quoted UTF-8 with backslash escaping.
Definition: Series of characters (letters, numbers, or symbols); double-quoted UTF-8 with backslash escaping.
·
Boolean
Declaration:
var myBool1 = true
Definition: One of two values: true or false.
·
Arrayvar
Declaration:
myArray1 = [
"a", "x", "t", "d" ]
Definition: Sequence of values,
comma-separated and enclosed in square brackets; values don't need to be of the
same type.
·
Objectvar
Declaration:
myObject1 = { "number":86
}
Definition: Unordered collection of
key/value pairs; comma-separated and enclosed in curly braces; the should be
strings and be distinct.
·
Nullvar
Declaration:
myNul1= null
Definition: Empty
Comments