复制代码 代码如下:
Productproduct = newProduct();
product.Name = "Apple";
product.Expiry = newDateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = newstring[] { "Small", "Medium", "Large"};
stringoutput = JavaScriptConvert.SerializeObject(product);
复制代码 代码如下:
[DataContract]
public class User
{
/// <summary>
/// 编号
/// </summary>
[DataMember]
public int UserId { get; set; }
/// <summary>
/// 用户名
/// </summary>
[DataMember]
public string UserName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[DataMember]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTime CreateDate { get; set; }
/// <summary>
/// 生日
/// </summary>
[DataMember]
[JsonConverter(typeof(JavaScriptDateTimeConverter))]
public DateTime Birthday { get; set; }
/// <summary>
/// 相关URL
/// </summary>
[DataMember]
public List<string> Urls { get; set; }
/// <summary>
/// 薪水
/// </summary>
[ScriptIgnore]//使用JavaScriptSerializer序列化时不序列化此字段
[IgnoreDataMember]//使用DataContractJsonSerializer序列化时不序列化此字段
[JsonIgnore]//使用JsonConvert序列化时不序列化此字段
public int Salary { get; set; }
/// <summary>
/// 权利级别
/// </summary>
[DataMember]
public Priority Priority { get; set; }
public User()
{
Urls = new List<string>();
}
}
参考:
新闻热点
疑难解答
图片精选