Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
With HTML5 web storage, websites can store data on a user's local computer. Before HTML5, we had to use JavaScript cookies to achieve this functionality. ... The Advantages of Web Storage
- More secure
- Faster
- Stores a larger amount of data
- Stored data is not sent with every server request
Note:
Local storage is per domain. All pages from one domain can store and access the same data.
by Valeri Tandilashvili
4 years ago
0
HTML
1
JSON
stands for
JavaScript Object Notation
JSON
is a way of communicating data with specific rules
JSON
is a syntax for storing and exchanging data
JSON
is text, written with JavaScript object notation The syntax is taken from
JavaScript
but
JSON
is portable with other languages
JSON
is a lightweight data-interchange format It's easy for humans to read and write It's easy for machines to parse and generate A common use of JSON is to exchange data
to/from
a web server
application/json
is the official Internet media type for
JSON
.json
is the
JSON
filename extension
by Valeri Tandilashvili
4 years ago
0
JSON
JSON Tutorial
1
Curly braces
{}
hold objects Square brackets
[]
hold arrays Data is represented in
key/value
pairs Each
key
is followed by colon
:
key/value
pairs are separated by comma
,
Array values are separated by comma
,
... Basic structure of
JSON
{
   "book": [

      {
         "id": "01",
         "language": "Java",
         "edition": "third",
         "author": "Herbert Schildt"
      },

      {
         "id": "07",
         "language": "C++",
         "edition": "second",
         "author": "E.Balagurusamy"
      }

   ]
}
by Valeri Tandilashvili
4 years ago
0
JSON
JSON Tutorial
1
string
- double-quoted Unicode
{ "name":"John" }
float
- precision floating-point number
{ "age":30.5 } 
integer
- number without a fractional component
{ "age":30 } 
boolean
- true or false
{ "sale":true }
array
- an ordered sequence of values
{ "employees":[ "John", "Anna", "Peter" ] }
object
- an unordered collection of
key:value
pairs
{ "employee":{ "name":"John", "age":30, "city":"New York" } } 
null
{ "middlename":null } 
by Valeri Tandilashvili
4 years ago
0
JSON
JS JSON
1
It is an ordered collection of values The values are separated by comma
,
These are enclosed in square brackets
[]
which means that array begins with
[
and ends with
]
{
   "books": [
      { "language":"Java" , "edition":"second" },
      { "language":"C++" , "lastName":"fifth" },
      { "language":"C" , "lastName":"third" }
   ]
}
by Valeri Tandilashvili
4 years ago
0
JSON
JSON Tutorial
1
It is an unordered set of
key/value
pairs Each key is followed by colon
:
key/value
pairs are separated by
comma
The keys must be strings and should be different from each other Objects should be used when the
key
names are arbitrary
strings
Objects are enclosed in curly braces
{}
, it starts with
{
and ends with
}
{
   "id": "011A",
   "language": "JAVA",
   "price": 500,
}
by Valeri Tandilashvili
4 years ago
0
JSON
JSON Tutorial
1
- a function
- a date
- a symbol
- undefined
by Valeri Tandilashvili
4 years ago
0
JSON
JS JSON
1
JSON is Like XML Because
- Both JSON and XML are "self describing" (human readable)
- Both JSON and XML are hierarchical (values within values)
- Both JSON and XML are language independent
- Both JSON and XML can be parsed and used by lots of programming languages
- Both JSON and XML can be fetched with an XMLHttpRequest
JSON is Unlike XML Because
+ JSON doesn't use end tag
+ JSON is shorter
+ JSON is quicker to read and write
+ JSON can use arrays
+ Better Performance
+ JSON can be parsed easily
+ JSON object has a type
+ All major JavaScript frameworks support JSON
+ Supported by all major JavaScript frameworks
+ Supported by most backend technologies
+ JSON is recognized natively by JavaScript (as object)
- JSON doesn't support comments
- JSON can not use attributes
- JSON offers poor extensibility as no namespace support
- Supports limited data types
JSON and XML examples JSON (size: 52 bytes)
{
   "company": Volkswagen,
   "name": "Vento",
   "price": 800000
}
XML (size: 79 bytes)
<car>
   <company>Volkswagen</company>
   <name>Vento</name>
   <price>800000</price>
</car>
Another example JSON
{
   "employees":[
      {"firstName":"John", "lastName":"Doe"},
      {"firstName":"Anna", "lastName":"Smith"},
      {"firstName":"Peter", "lastName":"Jones"}
   ]
}
XML
<employees>
  <employee>
    <firstName>John</firstName> <lastName>Doe</lastName>
  </employee>
  <employee>
    <firstName>Anna</firstName> <lastName>Smith</lastName>
  </employee>
  <employee>
    <firstName>Peter</firstName> <lastName>Jones</lastName>
  </employee>
</employees>
by Valeri Tandilashvili
4 years ago
0
JSON
JSON Tutorial
1
The following example shows how to convert an array into JSON
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

// Returns the JSON representation of a value (pretty printed)
echo json_encode($arr, JSON_PRETTY_PRINT);
Result of the above code
{
    "a": 1,
    "b": 2,
    "c": 3,
    "d": 4,
    "e": 5
}
The following example shows how the PHP objects can be converted into JSON
class Emp {
    public $name = "";
    public $hobbies  = [];
    public $birthdate = "";
}

$e = new Emp();
$e->name = "sachin";
$e->hobbies  = ["sport", "reading"];
$e->birthdate = date('Y-m-d', strtotime('2015-11-18'));

echo json_encode($e);
The above code will produce the following result
{"name":"sachin","hobbies":["sport","reading"],"birthdate":"2015-11-18"}
Decoding JSON in PHP (json_decode) The following example shows how PHP can be used to decode JSON objects
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

// Decoding into an object
var_dump(json_decode($json));

// Decoding into an array
var_dump(json_decode($json, true));
While executing, it will produce the following result
object(stdClass)#1 (5) {
  ["a"]=> int(1)
  ["b"]=> int(2)
  ["c"]=> int(3)
  ["d"]=> int(4)
  ["e"]=> int(5)
}
array(5) {
  ["a"]=> int(1)
  ["b"]=> int(2)
  ["c"]=> int(3)
  ["d"]=> int(4)
  ["e"]=> int(5)
}
by Valeri Tandilashvili
4 years ago
0
JSON
JSON Tutorial
1
JSON.parse()
Parses the data and converts it into a JavaScript object
let txt = '{"name":"John", "age":30, "city":"New York"}'

// Converts JSON string into a JavaScript object.
let obj = JSON.parse(txt);

// Puts the data into "p" element with id: demo
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;
by Valeri Tandilashvili
4 years ago
0
JSON
JavaScript
JS JSON
1
Results: 1580