2010-04-20 52 views
3

尝试序列化对象产品时出现错误。Newtonsoft.json抛出错误:数组不是一维数组

Product product = new Product(); 

product.Name = "Apple"; 

product.Expiry = new DateTime(2008, 12, 28); 

product.Price = 3.99M; 

product.Sizes = new string[3,2] { {"Small","40"}, {"Medium","44"}, {"Large","50"} }; 



string json = JsonConvert.SerializeObject(product);//this line is throwing an error 


Array was not a one-dimensional array 

有没有什么办法来序列二维阵列Newtonsoft.json

在此先感谢。 SIA

回答

0

newtonsoft是否支持序列化匿名对象?如果是这样,你可以尝试:

product.Sizes = new {Small = 40, Medium = 44, Large = 50}; 

你需要改变Product.Sizes仅仅是object