0

我不知道如何反序列化这个 json 字符串:

[ [ [ "JR10", "Test1", 142, 199, 66 ], [ "JR10", "Test2", 142, 199, 66 ] ] ]

放入数组内的数组中。

例如: messages[0]将包含一个数组包含"JR10", "Test1", 142, 199, 66 messages[0][0]将包含字符串"JR10"

4

2 回答 2

1

我不知道如何反序列化这个 json 字符串:

通常,当您想将 JSON 字符串反序列化为对象时,您会使用 JSON 序列化程序。例如使用内置JavaScriptSerializer类:

var json = "[ [ [ \"JR10\", \"Test1\", 142, 199, 66 ], [ \"JR10\", \"Test2\", 142, 199, 66 ] ] ]";
var serializer = new JavaScriptSerializer();
var result = serializer.Deserialize<object[][][]>(json);
Console.WriteLine(result[0][0][0]); // "JR10"
Console.WriteLine(result[0][0][1]); // "Test1"
Console.WriteLine(result[0][1][0]); // "JR10"
Console.WriteLine(result[0][1][1]); // "Test2"
...
于 2013-01-26T18:47:32.710 回答
0

There is an object that can deal with serialising and desierialising:

System.Web.Script.Serialization.JavaScriptSerializer

Code similar to this should achieve what you want.

JSONSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

Array[][] anArray = JSONSerializer.Deserialize<Array[][]>(JSON);
于 2013-01-26T18:45:35.433 回答