简体   繁体   English

在c#中反序列化数组的Json数组

[英]Deserialize Json array of array in c#

I am new to c# don't know how to get a JSON array of array stored in a 2d array. 我是c#的新手,不知道如何获得存储在2d数组中的JSON数组数组。 I am having a JSON file with students marks like 我有一个带有学生标记的JSON文件

[
    [10,5,4],
    [9,6,3]
]

and out of this I am using this code but getting error out at JArray 并且我正在使用此代码,但在JArray

JArray a = JArray.Parse(json);

I have tried some other approaches as well but nothing helped basically what I want to do is want to create a boolean 2D array which will be populated on the basis of the above JSON record and for that purpose I want to populate the array with JSON content. 我也尝试了其他一些方法,但基本上我想要做的事情就是创建一个布尔2D数组,它将在上面的JSON记录的基础上填充,为此,我想用JSON内容填充数组。

With the following valid JSON 使用以下有效的JSON

{ "data" : [
    [10,5,4],
    [9,6,3]
]
}

The following class was used to hold the parsed data 以下类用于保存已分析的数据

public class RootObject {
    public IList<IList<int>> data { get; set; }
}

which can be parsed using Json.Net 可以使用Json.Net解析

var root = JsonConvert.DeserializeObject<RoootObject>(json);

and the content accessed 和访问的内容

var x1 = root.data[0][1]; // 5
var x2 = root.data[1][1]; // 6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM