JSON is a lightweight data-interchange format.
JSON :- JavaScript Object Notation
Sending Data
var myObj =
{ "name":"John",
"age":31, "city":"New York" };
var myJSON =
JSON.stringify(myObj);
window.location = "demo_json.php?x=" + myJSON;
Receiving Data
var myJSON =
'{ "name":"John",
"age":31, "city":"New York" }';
var myObj =
JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.name;
JSON Syntax Rules
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
JSON Strings
{ "name":"Dilani" }
JSON Numbers
{ "age":19}
JSON Objects
{
"employee":{ "name":"Dilani", "age":19, "city":"Jaffna" }
}
Arrays
{
"employees":[ "Dilani", "Api", "Mino" ]
}
JSON Booleans
{ "sale":true }
{ "middlename":null }
Data Types
- a string
- a number
- an object (JSON object)
- an array
- a boolean
- null
JSON values cannot be one of the following data types:
- a function
- a date
- undefined
No comments:
Post a Comment