简体   繁体   中英

De-serialize JSON array in c#

I have a very odd JSON array as follows

[["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:

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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