前台的json数组转化为List<T>集合

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication13
{

//DataContract 和  DataMember不能缺少否则不能序列化成list<T>
[DataContract]
public class QuickFastPage
{
[DataMember]
private int index { get; set; }
[DataMember]
private string url { get; set; }
[DataMember]
private string pageName { get; set; }
}

public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request["_method"]) && Request["_method"] == "setQuickFast")
{
string pagePostData = Request["postData"];
if (!string.IsNullOrEmpty(pagePostData))
{
List<QuickFastPage> _Test = new List<QuickFastPage>();

DataContractJsonSerializer _Json = new DataContractJsonSerializer(_Test.GetType());
byte[] _Using = System.Text.Encoding.UTF8.GetBytes(pagePostData);
System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream(_Using);
_MemoryStream.Position = 0;

_Test = (List<QuickFastPage>)_Json.ReadObject(_MemoryStream);
}

}
}
}
}

posted on 2015-07-09 17:40  听哥哥的话  阅读(2342)  评论(0编辑  收藏  举报

导航