简体   繁体   English

在C#中反序列化JSON数组

[英]De-serialize JSON array in c#

I have a very odd JSON array as follows 我有一个很奇怪的JSON数组,如下所示

[["1","hello"],["2","hello2"],["3","hello3"],["",""],["",""],[null,null],[null,null],[null,null],[null,null],[null,null]] [[“ 1”,“ hello”],[“ 2”,“ hello2”],[“ 3”,“ hello3”],[“”,“”],[“”,“”],[null, null],[null,null],[null,null],[null,null],[null,null]]

I need to de-serialize in c# but there doesn't seem to be anything common to convert it to I tried string but then I get the follow error: 我需要在C#中反序列化,但是似乎没有什么普通的东西可以将其转换为我尝试过的字符串,但是随后出现以下错误:

Type string is not supported for deserialization of an array. 数组反序列化不支持字符串类型。

This is the code I tried: 这是我尝试的代码:

string jsonString = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<string>(json);

How would you get at the strings in the JSON? 您将如何获取JSON中的字符串?

You could deserialize it to an array of string arrays: 您可以将其反序列化为字符串数组的数组:

string[][] jsonString = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<string[][]>(json);

Or maybe a list of string-tuples (Dictionary could be problematic due to the lack of unique keys): 也许还有一个字符串元组列表(由于缺少唯一键,字典可能会出现问题):

List<Tuple<string, string>> jsonString = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialze<List<Tuple<string, string>>(json);

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

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