What is serialization ?
Serialization is a process of translating an object into a format, that can be stored in a file or memory and restructured later in the same or another environment. There are different types of serializations like JSON, XML etc..
Example :
class Person
{
string name;
int age;
string address;
}
suppose there are 3 objects of class person .. p1, p2 and p3
now serialize these object into Json
{
"p1":{
"name":"Rabi",
"age":"23",
"address":"Kolkata"
} ,
"p2":{
"name":"Suman",
"age" : "26",
"address" : "Delhi"
} ,
"p3":{
"name":"kumar",
"age": "30",
"address" : "Mumbai"
}
}
Create Json using javascript
var Person=function(){
this.name="";
this.age;
this.address="";
}
var p1=new Person();
p1.name="Rabi";
p1.age=23;
p1.address="Kolkata";
var p2=new Person();
p2.name="Suman";
p2.age=26;
p2.address="Delhi";
var p3=new Person();
p3.name="Kumar";
p3.age=30;
p3.address="Mumbai";
var personMap={};
personMap ["p1"] = p1 ; personMap ["p2"] = p2 ; personMap ["p3"] = p3 ;
alert( JSON.stringify (personMap) ); // convert the personMap object into string
Serialization is a process of translating an object into a format, that can be stored in a file or memory and restructured later in the same or another environment. There are different types of serializations like JSON, XML etc..
Example :
class Person
{
string name;
int age;
string address;
}
suppose there are 3 objects of class person .. p1, p2 and p3
now serialize these object into Json
{
"p1":{
"name":"Rabi",
"age":"23",
"address":"Kolkata"
} ,
"p2":{
"name":"Suman",
"age" : "26",
"address" : "Delhi"
} ,
"p3":{
"name":"kumar",
"age": "30",
"address" : "Mumbai"
}
}
Create Json using javascript
var Person=function(){
this.name="";
this.age;
this.address="";
}
var p1=new Person();
p1.name="Rabi";
p1.age=23;
p1.address="Kolkata";
var p2=new Person();
p2.name="Suman";
p2.age=26;
p2.address="Delhi";
var p3=new Person();
p3.name="Kumar";
p3.age=30;
p3.address="Mumbai";
var personMap={};
personMap ["p1"] = p1 ; personMap ["p2"] = p2 ; personMap ["p3"] = p3 ;
alert( JSON.stringify (personMap) ); // convert the personMap object into string
No comments:
Post a Comment