尝试序列化对象产品时出错。
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 :(得分:3)
Json.NET不支持多维数组。改为使用锯齿状数组。
答案 1 :(得分:0)
newtonsoft是否支持序列化匿名对象?如果是这样,你可以尝试:
product.Sizes = new {Small = 40, Medium = 44, Large = 50};
您需要将Product.Sizes
更改为object