json.net的使用起来很简单的
可以到它的官方网站去下载它的组件(注意版本问题哦)
http://www.codeplex.com/Json/Release/ProjectReleases.aspx?ReleaseId=18825
安装后 引用
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using Newtonsoft.Json;
- using System.Collections;
- using Newtonsoft.Json.Utilities;
- using System.Runtime.Serialization;
- using System.Text;
- using System.Collections.Generic;
- using System.IO;
- public partial class _Default : System.Web.UI.Page
- {
- public static string str = "hello";
- protected void Page_Load(object sender, EventArgs e)
- {
-
- BaseClass bs = new BaseClass();
- bs.Title = "hello world";
- bs.Content = "this is ok";
- bs.Userip = "127.0.0.1";
-
- Hashtable hs1 = new Hashtable();
- hs1.Add("username", "dwqdq");
- hs1.Add("pwd", "656");
-
- string json1 = JavaScriptConvert.SerializeObject(bs);
- string json2 = JavaScriptConvert.SerializeObject(hs1);
- Response.Write(json1);
- Response.Write(json2);
-
- }
- }
BaseClass.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public class BaseClass
- {
- public BaseClass()
- {
-
-
-
- }
- string _title;
- public string Title
- {
- get { return _title; }
- set { _title = value; }
- }
- string _content;
- public string Content
- {
- get { return _content; }
- set { _content = value; }
- }
- string _userip;
- public string Userip
- {
- get { return _userip; }
- set { _userip = value; }
- }
- }
是不是很简单?