Newtonsoft.json抛出错误:数组不是一个一维数组 [英] Newtonsoft.json throwing error: Array was not a one-dimensional array

查看:250
本文介绍了Newtonsoft.json抛出错误:数组不是一个一维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将对象序列化产品的时候得到一个错误。

I am getting an error when trying to serialize an object products.

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二维数组

Is there any way to serialize a two dimensional array with Newtonsoft.json

在此先感谢。
SIA

Thanks in Advance. SIA

推荐答案

Json.NET不支持多维数组。使用交错数组来代替。

Json.NET doesn't support multi-dimensional arrays. Use a jagged array instead.

<一个href=\"http://www.c-sharpcorner.com/uploadfile/mahesh/workingwitharrays11232005064036am/workingwitharrays.aspx\" rel=\"nofollow\">http://www.c-sharpcorner.com/uploadfile/mahesh/workingwitharrays11232005064036am/workingwitharrays.aspx

这篇关于Newtonsoft.json抛出错误:数组不是一个一维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆