Newtonsoft.json抛出错误:数组不是一维数组

时间:2010-04-20 21:58:23

标签: asp.net multidimensional-array json.net

尝试序列化对象产品时出错。

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

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

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

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

您需要将Product.Sizes更改为object