JSON

Post on 29-Nov-2014

104 views 0 download

Tags:

description

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

Transcript of JSON

Team Members

1. Anum Hanif2. Farina Khan3. Hafiza Areeba 4. Haya Samar5. Maheen Ashraf6. Ramsha Arif7. Sadaf Allahdin8. Sobia Hashmi9. Sundus Munawar10. Zara Tariq

What is JSON?

• Lightweight data-interchange format

• Subset of JavaScript

• Easy for humans to read and write

• Easy for machines to parse and generate

• Language independent

JSON

Properties of JSON

• Human and machine readable format.

• Strict syntax and parsing requirements.

• Represents the most general computer science

data structures like records, lists and trees.

JSON

Data Interchange

• JSON is a simple, common representation of

data.

• Communication between servers and browser

clients.

JSON

Where to use JSON?• It is useful when writing any kind of JavaScript-

based application.

• I t is used primarily to transmit data between a

server and web application.

• JSON with PHP

• JSON with Perl

• JSON with Python

• JSON with JavaScript

JSON

Where to use JSON?• JSON with PHP

• json_encode

• json_decode

• json_last_error

• JSON with Perl

• to_json

• from_json

• convert_blessed

JSON

Where to use JSON?

JSON

• JSON with Python

• encode

• decode

• JSON with Javascript

• JSON.stringify

• JSON.parse

Why JSON ?• JSON is syntax for storing and exchanging text

information.

• The JSON text format is syntactically identical

to the code for creating JavaScript objects.

• Because of this similarity, instead of using a

parser, a JS program can use the built-in

functions and execute JSON data to produce

native JavaScript objects.

JSON

• 3 Reasons why you should use JSON

• Clean data

• Efficiency

• Scalability

JSON

•As compared to XML, JSON is

• smaller

• faster and

• easier to parse

Why JSON ?

How to use it..?• JSON syntax is a subset of JavaScript syntax• Json Syntax Rules• Data is in name/value pairs• Data is separated by commas• Curly braces hold objects• Square brackets hold arrays

• JSON Name/Value Pairs• JSON data is written as name/value pairs• Example

• "firstName" : "John"

JSON

How to use it..?• JSON values can be

A number (integer or floating point) A string (in double quotes) A Boolean (true or false) An array (in square brackets) An object (in curly brackets) null

• JSON Objects JSON objects are written inside curly brackets Objects can contain multiple name/values pairs

• Example{ "firstName":"John" , "lastName":"Doe" }

JSON

How to use it..?Simple Example

JSON

How to use it..?Result

JSON

JSON vs. XML

JSON

JSON

• JSON is a text-based format.

• JSON data types: string, number, array, Boolean.

• JSON does not contain start and end tags.

• JSON include arrays.• JSON does not have

support for Namespaces.

XML

• XML is a Markup Language.

• XML data are all string.

• Xml contain start and end tags.

• XML doesn't include arrays.

• XML supports Namespaces.

JSON vs. XML

<?xml version=“1.0” encoding=“utf-8”?>

<students> <student> <name>Ali</name> <age>20</age> <gender>male</gender> </student> <student> <name>Bilal</name> <age>21</age> <gender>male</gender> </student> </students>

“students”= [

{“name”: “Ali”, “age”: “20”,

“gender”: “Male”},

{“name”: “Bilal”, “age”: “21”,

“gender”: “Male”}

]

JSON

JSON XML

JSON

Examples Of JSON

Examples Of JSON• Android weather app: JSON, HTTP, Async Task and Openweathermap

HTTP Connection

OpenWeatherMap API

Async Task

JSON Object and Parser

Display DataJSON