Serialization and deserialization of JSON in. Net

Source: Internet
Author: User

Penson class

Using system;using system.collections.generic;using system.linq;using system.web;namespace  Json_Demo{    public class Penson    {         private string _name;         private int _age;        private string _ address;        public string address         {            get  { return _address; }             set { _address = value; }        }         public int Age         {            get { return _age; }             set {                 if  (_age < 100 && _ age > 0)                  {                     _age = value;                 }                 else                 {                     _age = 0;                 }            }         }        public string Name         {             get { return _name; }             set { _name = value; }        }     }}

Background code:

Using system;using system.collections.generic;using system.linq;using system.web;using  system.web.ui;using system.web.ui.webcontrols;//introduction of related namespaces using system.web.script;using  system.web.script.serialization;namespace json_demo{    public partial  class webform1 : system.web.ui.page    {         protected void page_load (object sender, eventargs e)          {             Penson p1 = new penson ();             p1. name =  "JSON";             p1. Age = 120;            p1. address =  "Jiangxi Gao an";                          javascriptserializer json1 = new javascriptserializer ();             string str = json1. Serialize (p1);//json serialization             session["STR1"]  = str;//session page value         }    }} foreground <%@ page language= "C #"  autoeventwireup= "true"  codebehind= "WebForm1.aspx.cs"   inherits= "Json_demo.webform1"  %>//import namespace <%@ import namespace= "Json_demo"  %><%@  import namespace= "System.Web.Script.Serialization"  %><! doctype html>

: 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/4D/B3/wKioL1RXhF_BcvoIAADfqom1PAw324.jpg "title=" Qq20141103213108.jpg "alt=" Wkiol1rxhf_bcvoiaadfqom1paw324.jpg "/>

This article is from the "Day to Up" blog, so be sure to keep this source http://1433189426.blog.51cto.com/8055494/1571439

Serialization and deserialization of JSON in. Net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.