日期:2014-05-17 浏览次数:21006 次
public static string ToJSON(object obj)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(obj);
}
Province p = new Province();
p.Id = 123;
p.Name = "北京";
Response.Write(ToJSON(p));//{"Id":123,"Name":"北京"}
class Program
{
static void Main(string[] args)
{
Province p = new Province();
p.Id = 123;
p.Name = "北京";
p.text = new Text()
{
Content = "123456"
};
Console.WriteLine(ToJSON(p));
}
public static string ToJSON(object obj)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(obj);
}
}
public class Province
{
public int Id { get; set; }
public string Name { get; set; }
public Text text { get; set; }
}
public class Text
{
public string Content { get; set; }
}