json.net的使用起来很简单的
可以到它的官方网站去下载它的组件(注意版本问题哦)
http://www.codeplex.com/Json/Release/ProjectReleases.aspx?ReleaseId=18825
安装后 引用
- usingSystem;
- usingSystem.Data;
- usingSystem.Configuration;
- usingSystem.Web;
- usingSystem.Web.Security;
- usingSystem.Web.UI;
- usingSystem.Web.UI.WebControls;
- usingSystem.Web.UI.WebControls.WebParts;
- usingSystem.Web.UI.HtmlControls;
- usingNewtonsoft.Json;
- usingSystem.Collections;
- usingNewtonsoft.Json.Utilities;
- usingSystem.Runtime.Serialization;
- usingSystem.Text;
- usingSystem.Collections.Generic;
- usingSystem.IO;
- publicpartialclass_Default:System.Web.UI.Page
- {
- publicstaticstringstr="hello";
- protectedvoidPage_Load(objectsender,EventArgse)
- {
- //第一种
- BaseClassbs=newBaseClass();
- bs.Title="helloworld";
- bs.Content="thisisok";
- bs.Userip="127.0.0.1";
- //第二种
- Hashtablehs1=newHashtable();
- hs1.Add("username","dwqdq");
- hs1.Add("pwd","656");
- stringjson1=JavaScriptConvert.SerializeObject(bs);
- stringjson2=JavaScriptConvert.SerializeObject(hs1);
- Response.Write(json1);
- Response.Write(json2);
- }
- }
BaseClass.cs
- usingSystem;
- usingSystem.Data;
- usingSystem.Configuration;
- usingSystem.Web;
- usingSystem.Web.Security;
- usingSystem.Web.UI;
- usingSystem.Web.UI.WebControls;
- usingSystem.Web.UI.WebControls.WebParts;
- usingSystem.Web.UI.HtmlControls;
- ///<summary>
- ///BaseClass的摘要说明
- ///</summary>
- publicclassBaseClass
- {
- publicBaseClass()
- {
- //
- //TODO:在此处添加构造函数逻辑
- //
- }
- string_title;
- publicstringTitle
- {
- get{return_title;}
- set{_title=value;}
- }
- string_content;
- publicstringContent
- {
- get{return_content;}
- set{_content=value;}
- }
- string_userip;
- publicstringUserip
- {
- get{return_userip;}
- set{_userip=value;}
- }
- }
是不是很简单?
原文链接:https://www.f2er.com/json/290844.html