今天我们来探讨一下关于 使用JavaScriptSerializer的Serialize方法进行Json序列化.
在这里我们要用到反射,所以,对于反射也可以顺便学习一下.
注意,我这里是用Vs2008来编写的,所以Vs2008以前的版本,需要读者自己相应的改一下,~_~!
首先我们创建一个webapplication工程,
添加一个WebService.htm文件,
页面代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script src="ExtJs/ext-base.js" type="text/javascript"></script>
<script src="ExtJs/ext-all.js" type="text/javascript"></script>
</head>
<body>
<input id="Button1" onclick="getValue();" type="button" value="返回" />
<textarea id="log" cols="40" rows="10"></textarea>
然后我们加入要引用的ext-base.js和ext-all.js两个ExtJs文件,这两个文件需要读者到www.extjs.com去下载.
接下来我们创建一个test.asmx文件,代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.ServiceModel.Web;
using System.ServiceModel.Dispatcher;
using Component;
namespace WebApplication1
接下来创建一个ExtendMethod.cs文件,存放Json序列化的扩展方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Collections;
using System.Reflection;
namespace Component
![]()