日期:2014-05-18 浏览次数:20553 次
// 引用 using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Json;
------解决方案--------------------
//最后改了下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; namespace ConsoleApplication1 { [DataContract] public sealed class FooDef { [DataMember(Name = "ID", IsRequired = true)] public string ID { get; set; } [DataMember(Name = "Order", IsRequired = true)] public string Order { get; set; } } class Program { static void Main(string[] args) { string bar = "[{\"ID\":\"3\",\"Order\":\"9\"},{\"ID\":\"1\",\"Order\":\"6\"},{\"ID\":\"2\",\"Order\":\"8\"}]"; List<FooDef> newEntities = Deserialize<FooDef>(bar); var s = from l in newEntities orderby l.ID select l; } static List<T> Deserialize<T>(string str) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(List<T>)); using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(str))) { List<T> entities = (List<T>)json.ReadObject(stream); stream.Close(); return entities; } } } }