[c#]代码库
using System;
using System.Web.Script.Serialization;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Test
{
class Program
{
static void Main( string[] args)
{
Customer cc = new Customer { Unid = 1, CustomerName = "John" };
string strJson = ScriptSerialize< Customer>(cc);
Console.WriteLine(strJson);
Customer c1 = ScriptDeserialize<Customer >(strJson);
Console.WriteLine(c1.Unid + " " + c1.CustomerName);
Console.ReadLine();
}
public class Customer
{
public int Unid { get; set; }
public string CustomerName { get; set; }
}
public static string ScriptSerialize( Customer customer)
{
JavaScriptSerializer js = new JavaScriptSerializer ();
return js.Serialize(customer);
}
public static Customer ScriptDeserialize(string strJson)
{
JavaScriptSerializer js = new JavaScriptSerializer ();
return js.Deserialize< Customer>(strJson);
}
public static string ScriptSerialize<T>(T t)
{
JavaScriptSerializer js = new JavaScriptSerializer ();
return js.Serialize(t);
}
public static T ScriptDeserialize<T>( string strJson)
{
JavaScriptSerializer js = new JavaScriptSerializer ();
return js.Deserialize<T>(strJson);
}
}
}
by: 发表于:2018-01-12 14:33:27 顶(0) | 踩(0) 回复
??
回复评论