我正在尝试用Newtonsoft序列化两个对象,但是没有给出结果:
{
"product_id" : 1234,
"desc" : {
"name" : "Product 1",
"tag" : 1234
}
}
public class Product
{
[JsonProperty("product_id")]
public Int64 ProductId{ get; set; }
[JsonProperty("desc")]
public Desc Desc { get; set; }
}
public class Desc
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("tag")]
public Int64 Tag { get; set; }
}
当我尝试序列化时,我正在使用:
Product product = new Product
{
ProductId = 123456
};
string json = JsonConvert.SerializeObject(product , Formatting.Indented);
我也不确定如何填充我的Desc对象...