How to use json data using php - Web Development

How to use json data using php

Json is javascript object notation . It used for data exchange on server . Json is light weight data exchange format which is useful for server & website communication .

Take a real life example Suppose Website A in java and Website B is in PHP but if they want to communicate with each other or wants to exchange data with each other then they will use Json or xml .

Json is very easy to use & language independent .Json is used to storing and transport data on server . Json is text format so it can be transported anywhere

XML is difficult to parse than JSON.
JSON is parsed into a ready-to-use JavaScript object. JSON can use array for multiple data

Different Json data types

a string , a number , boolean , an array , an object (JSON object)

this is json object and we can convert it to javascript object using JSON.parse();  We write json data or object withing curly braces { } .Json data must be in key and value format , both key and value separated by single colon .

A common use of Javascript object notation is to exchange data to/from a web server.

When receiving data from a server, the data is always a string form.

we parse the data using JSON.parse()&then data becomes javascript object

Now using php code we can convert to json

Output of code

{“name”:”dheeraj”,”age”:”37″,”state”:”haryan”} This is output is in JSON format & we got this output by using json_encode(); function of php

Lets see another example of json ( How to use loop in json)

Output of code

Using loop in json

Employee Job
Email
Cell Number

Now how to access its property through loop

Output of code :

Using loop in json

comupting
[email protected]
211882

How array works in json

Output of code

Chemistry

data = jObj.subjects[2]; I gave index 2 so output is chemistry

Leave a Reply

Your email address will not be published. Required fields are marked *