• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Json
 

Json

on

  • 1,616 views

Json description

Json description

Statistics

Views

Total Views
1,616
Views on SlideShare
1,615
Embed Views
1

Actions

Likes
2
Downloads
55
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Json Json Presentation Transcript

    • JSON JavaScript Object Notation Developed by: Musavir Iftikhar Jan 2007
    • Introduction
      • A lightweight data-interchange format.
      • Easy for humans to read and write.
      • Alternative solution of XML
      • A text format that is completely language independent
      • Uses convention like C and Java
      • It is JavaScript based Language
    • JSON values
      • A collection of name/value pairs. In various languages, this is realized as an object , record, struct, dictionary, hash table, keyed list, or associative array
      • An ordered list of values. In most languages, this is realized as an array , vector, list, or sequence.
    • Data types in JavaScript
      • Primitive data types are as followings
      • Undefined
      • Null
      • Boolean
      • Number and String .
      • <script> int a = 5;
      • Alert (typeof a) // will show int
      • </script>
    • Built-in Objects in JavaScript
      • Built-in JavaScript objects
      • Image, array and object
      • Following is an instance of image built-in javascript object
      • <script>
      • var Image1 = new Image();
      • Image1.src = “bird. gif &quot;;
      • </script>
    • New Object in JavaScript
      • A function in JavaScript is an Object
      • <script>
      • function myFunc(){ } var myObject = new myFunc(); alert(typeof myObject);  // displays &quot;object“
      • </script>
    • Constructor of object
      • A constructor is the default value of function
      • <script>
      • function myFunc(){  return 5; } var myObject = myFunc(); alert(typeof myObject); // displays &quot;number“
      • </script>
    • Object function more
      • Function with default value
      • <script>
      • function myFunc(){  this.StringValue = &quot;This is a String&quot;; } var myObject = new myFunc(); var myObject2 = new myFunc(); alert(myObject2.StringValue); // displays &quot;This is a String“
      • </script>
    • Passing values to Objects
      • Function that takes Object’s value
      • <script>
      • function myFunc(StringValue){  this.StringValue = StringValue; } var myObject = new myFunc(&quot;This is myObject's string&quot;); var myObject2 = new myFunc(&quot;This is a String&quot;); alert(myObject.StringValue); // displays &quot;This is myObject's string&quot; alert(myObject2.StringValue); // displays &quot;This is a String“
      • </script>
    • Object with methods
      • A Object with functions is a function that uses other functions for its functionality.
      • <script>
      • function Circle(radius){  this.radius = radius;  this.getArea = getArea;  this.getCircumference = getCircumference; }
      • function getArea(){
      • return (this.radius*this.radius*3.14);
      • }
      • function getCircumference(){
      • var diameter = this.radius*2;
      • var circumference = diameter*3.14;
      • return circumference;
      • }
    • Code.. continue
      • var bigCircle = new Circle(100);
      • var smallCircle = new Circle(2);
      • alert(bigCircle.getArea()); // displays 31400
      • alert(bigCircle.getCircumference()); // displays 618
      • alert(smallCircle.getArea()); // displays 12.56
      • alert(smallCircle.getCircumference()); // displays 12.56
      • </script>
      • Note: this key world always point to the variable of that object that is
      • instantiated.
      • The functions that Object using refer to the variable of Object function
      • when they
      • Come across this keyword as this.radius means the radius of the Object
      • function Circle.
    • Inner or Nested functions
      • Inner Function is created inside the function for Objected Oriented programming style. It is clear and easy to write.
      • Note: the constructor function argument variable must be accessed by using key world this
      • <script>
      • function Circle(radius){  this.radius = radius;  this.getArea = function(){    return (this.radius*this.radius*3.14);  }  this.getCircumference = function(){    var diameter = this.radius*2;    var circumference = diameter*3.14;    return circumference;  } }
    • Code…continue
      • var bigCircle = new Circle(100); var smallCircle = new Circle(2); alert(bigCircle.getArea()); // displays 31400 alert(smallCircle.getCircumference()); // displays 12.56
      • </script>
    • JSON Object
      • object
        • {}
        • { members }
      • members
        • pair
        • pair , members
      • pair
        • string : value
      • array
        • [] [ elements ]
      • elements
        • value value , elements
    • JSON Object
      • value
        • string number object array true false null
      • string
        • &quot;&quot; &quot; chars &quot;
      • chars
        • char char chars
    • JSON Object
      • char
        • any-Unicode-character-      except- &quot; -or- -or-      control-character &quot; /  f u four-hex-digits
      • number
        • int int frac int exp int frac exp
    • JSON Object
      • int
        • digit digit1-9 digits - digit - digit1-9 digits
      • frac
        • . digits
      • exp
        • e digits
      • digits
        • digit digit digits
      • e
        • e e+ e- E E+ E-
    • Using JSON
      • JSON is available for two sides
      • Server side JSON
      • Format is written in the server specific language as C, C++, C#, java, PHP etc.
      • It is used to decode the client request
      • Client side JSON
      • JavaScript is used to encode the JSON response to convert it into text representation of receiving Object
    • Server side Requirements
      • Need JSON file written in support server side language as for PHP JSON.php
      • Include into page and create a new instance
      • <?php
      • require_once &quot;JSON.php&quot;;
      • //create a new instance of Services_JSON
      • $json = new Services_JSON();
      • ?>