For lightweight applications, the client serializes and deserializes available JSON-json.parse () and json.stringify (),
But when the server-side serialization and deserialization, I encountered some problems, I took three ways, three ways to serialize and deserialize different ways, the comparison please click here to see.
Here's the code for my operation:
Front desk:
1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
234 <title> Untitled Page </title>
5 <script type= "Text/javascript" src= ". /js/jquery-1.3.min.js "></script>
6 <script type= "Text/javascript" src= ". /js/json2.js "></script>
7 <script type= "Text/javascript" >
8 function GetValue ()
9 {
$.get ("Process.aspx", {Action: "get"}, function (data, textstatus) {
One var name=$ ("#TName") [0];
var address=$ ("#TAddress") [0];
var age=$ ("#TAge") [0];
var obj=json.parse (data);
Name.value=obj. Name;
Address.value=obj. address;
Age.value=obj. Age;
18});
19}
20
function SetValue ()
22 {
var person=new person ($ ("#TName") [0].value,$ ("#TAddress") [0].value,$ ("#TAge") [0].value];
var str=json.stringify (person);
alert (str);
$.post ("Process.aspx", {Action: "Post", Jsonstr: "" + str + "}, function (data, textstatus) {
Alert ("Send Success");
28});
29}
30
-Function person (name,address)
32 {
this. Name=name;
this. address=address;
35}
</script>
3738<body>
<form id= "Form1" runat= "Server" >
<div>
<table>
<tr>
<td> name:</td>
<td><input type= "text" id= "Tname"/></td>
</tr>
<tr>
<td> Address:</td>
<td><input type= "text" id= "taddress"/></td>
</tr>
M <tr>
Wuyi <td> Age:</td>
<td><input type= "text" id= "Tage"/></td>
</tr>
</table>
<table>
<tr>
<td><input type= "button" onclick= "GetValue ();" value= "Load data ></td>
<td><input type= "button" value= "Update Data" onclick= "SetValue ()" ></td>
</tr>
</table>
</div>
</form>
63</body>
64