将JSON字符串反序列化为数组或列表

时间:2018-12-18 22:58:09

标签: json asp.net-mvc

我需要反序列化JSON字符串并将其存储到列表或数组中。因此使用了下面的给出代码

dynamic jr = JsonConvert.DeserializeObject(paramList);

foreach (var item.Value in jr)
{

} 

paramList中的字符串值就像

{"0":["1234","2222","4321","211000","90024","12","2121","322223","2332","3232"],"1":["0856","6040222","175002","23572","","","","","",""]}

item中的字符串值。值类似于-

{[  "1234",  "2222",  "4321",  "211000",  "900224",  "12",  "2121",  "322223",  "2332",  "3232"]}

因此,请帮助我迭代此字符串,以便可以将其放入数组或列表中。

谢谢

1 个答案:

答案 0 :(得分:0)

试试这个-

var jr = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(paramList);

foreach (var item in jr)
{
     // item.Value
} 

更新1:

现在,如果您只想将所有值都放入列表中,则可以使用以下内容-

var allValues = jr.SelectMany(x => x.Value).ToList();