1
json.net可以將類對象序列化爲簡單字典嗎?使用json將對象序列化爲字典,net
public class CommitData
{
public AddressDTO Property { get; set; }
public DateTime? Appointment { get; set; }
public DateTime? Closed { get; set; }
public DateTime? Created { get; set; }
public string LenderRef { get; set; }
public string YearBuilt { get; set; }
public IDictionary<string, object> Custom { get; set; }
}
public class AddressDTO
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string Postcode { get; set; }
}
當序列化我想:
{
"Property.Address1": "",
"Property.Address2": "uyg",
"LenderRef": "yguyg",
"Closed": date_here }
和反序列化同樣像上面一個JSON字符串到CommitData對象?
你看這個:http://stackoverflow.com/questions/15333820/how-to-flatten-a-referenced-object-into-two-json-net-properties-on-the-referer?一般來說,它似乎不能用JSON.NET完成。無論如何,JSON.NET會將你的地址序列化到它自己的對象中,所以當反序列化時,你將得到一個帶有'AddressDTO'屬性的'CommitData'對象,你可以像普通一樣使用'.'來訪問它。 – Tallmaris