static void Main() { List <UserInfo> infos = new List <UserInfo>(); infos.Add(new UserInfo() { UserName = "******", UserLocation = "US", UserBirth = new DateTime(2000, 01, 01) }); infos.Add(new UserInfo() { UserName = "******", UserLocation = "JP", UserBirth = new DateTime(2001, 02, 02) }); infos.Add(new UserInfo() { UserName = "******", UserLocation = "KR", UserBirth = new DateTime(2002, 03, 03) }); SerializeEx.Serialization(infos, Environment.CurrentDirectory + "\\infos"); var loadInfos = SerializeEx.DeSerialization <List <UserInfo> >(Environment.CurrentDirectory + "\\infos"); foreach (var i in loadInfos) { string outputResult = "Name : " + i.UserName + " Location : " + i.UserLocation + " Birth : " + i.UserBirth; Console.WriteLine(outputResult); } }
/// <summary> /// 调用RestFull服务的Post方法 /// </summary> /// <param name="url">url</param> /// <param name="obj">参数对象</param> /// <returns>返回字符串</returns> public static string Post(string url, object obj) { var request = CreateRequest(url, WebRequestMethods.Http.Post); string json = SerializeEx.RuntimeJsonSerializerObject(obj); var bytes = Encoding.UTF8.GetBytes(json); request.ContentLength = bytes.Length; using (var writeStream = request.GetRequestStream()) { writeStream.Write(bytes, 0, bytes.Length); } return(Request(request)); }
public static void Test() { try { var bassAddress = new Uri("http://127.0.0.1:7789/"); var str = bassAddress.ToString(); //var str = HttpRequest(@"http://127.0.0.1:7789/PersonInfoQuery/", "xcvzxcv"); //var user = SerializeEx.RuntimeJsonDeserializeObject<User>(str); User addUser = new User() { Id = "5", Name = "起赵鼎", Age = 19, Birthday = DateTime.Now.AddDays(-1547) }; var jsonAdd = RestFullClientDemo.Post(@"http://127.0.0.1:7789/PersonInfoQuery/user", addUser); var jsonGet = RestFullClientDemo.Get(@"http://127.0.0.1:7789/PersonInfoQuery/5"); var userGet = SerializeEx.RuntimeJsonDeserializeObject <User>(jsonGet); userGet.Name = "mm"; userGet.Age = 25; var jsonPut = RestFullClientDemo.Put(@"http://127.0.0.1:7789/PersonInfoQuery/user", userGet); var jsonGet2 = RestFullClientDemo.Get(@"http://127.0.0.1:7789/PersonInfoQuery/5"); var userGet2 = SerializeEx.RuntimeJsonDeserializeObject <User>(jsonGet2); var jsonDel = RestFullClientDemo.Delete(@"http://127.0.0.1:7789/PersonInfoQuery/5"); var jsonGet3 = RestFullClientDemo.Get(@"http://127.0.0.1:7789/PersonInfoQuery/5"); //var userGet3 = SerializeEx.RuntimeJsonDeserializeObject<User>(jsonGet3); } catch (Exception ex) { Loger.Error(ex); } }