json序列化列表中的列表 [英] json serialize list in list

查看:139
本文介绍了json序列化列表中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在json中得到一个带有列表的列表,并想将json转换为matrixList对象,但无法使其正常工作,我收到此错误

I get a list with list in json And want to convert the json to matrixList Object but cant get it to work Im getting this error

System.Collections.Generic.Dictionary`2[System.String,System.Object]

这是我的代码

JavaScriptSerializer json_serializer = new JavaScriptSerializer();
matrixList mxList = (matrixList)json_serializer.DeserializeObject("{ \"matrix\": "[[\"1\",\"email1@gmail.com\"],[\"2\",\"email2@gmail.com\"],[\"3\",\"email3@gmail.com\"],[\"4\",\"email4@gmail.com\"]]" }");

Json的值仅是一个示例

The values of the Json is just an example

public class matrixList
{
    public List<List<string>> matrix { get; set; }
}

然后我的问题为什么不起作用?我已经搜索了该错误,只发现了一些具有Json语法错误的消息,但是我看不到任何错误.

My question then why wont it work I have searched on the error and only found some with Json syntax error but Im not able to see any error.

帮助寻求帮助

推荐答案

尝试首先添加RootObject.

Try adding a RootObject first.

public class RootObject
{
public RootObject(){}
public List<string> itemList{get;set;}
}

然后尝试反序列化为RootObject类型. 在对列表进行反序列化时,此功能可与Newtonsoft.JSON序列化程序一起使用.

Then try deserializing to the RootObject type. When deserializing Lists this works with Newtonsoft.JSON serializer.

serializer.DeserializeObject<RootObject>(jsonInput);

这篇关于json序列化列表中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆