時,我有一個數據傳輸對象類產品ASP.net的Web API:改變類的名稱序列化
public class ProductDTO
{
public Guid Id { get; set; }
public string Name { get; set; }
// Other properties
}
當Asp.net串行化JSON(使用JSON.NET
)或XML
對象,它生成ProductDTO
對象。
不過,我想序列化過程中改名換姓,從ProductDTO
到Product
,使用某種屬性:
[Name("Product")]
public class ProductDTO
{
[Name("ProductId")]
public Guid Id { get; set; }
public string Name { get; set; }
// Other properties
}
我怎樣才能做到這一點?
將實例序列化爲JSON時名稱ProductDTO的名稱如何?畢竟JSON是無類型的,當我嘗試用JSON.NET序列化一個實例時,類名不存在。 – aknuds1 2013-02-13 11:11:29