Thursday, 08 August 2019 08:16

What is json and how to parse json data

Written by 
Rate this item
(0 votes)

JSON is JavaScript Object Notation 

 In case of exchanging data between a web browser and server, 

only text data can be allowed. JSON is text, we are able to 

convert any javascript object into JSON, then send JSON to server.

Likewise we can convert any JSON received from server into 

javascript objects. So this his how we can do things with javascript

objects without parsing and translations hassles.

Following is a example shows how to send and receive data using Json - 

When sending, If you have data in a JavaScript object, convert the 

object into JSON and send it to server: 

var theObj = {name: "Mridul", age: 32, city: "California"};

var theJson = JSON.stringify(theObj);

window.location = "demo_json.php?x=" + theJson;

When receiving data, you get data in JSON format, then convert it 

into a JavaScript object :

var theJson = '{"name":"Rony", "age":31, "city":"New York"}';

var theObj = JSON.parse(theJson);

document.getElementById("demos").innerHTML = theObj.name;

So finally, JSON format is text only, it can be sent easily to and from 

a server. 

Hope you liked it, don't forget to share and like it.

 

Read 38 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments