JavaScriptSerializer。如何从JSON反序列化字符串数组?

时间:2016-11-15 01:12:06

标签: c# .net wpf javascriptserializer

这是我用来反序列化的模型。

C#

public class Info
{
    public string description { get; set; }
    public string[] tags { get; set; }
}

这是我要反序列化的JSON。

JSON

{
    "description" : "aeiou",
    "tags" : [ "a", "e", "i", "o" ]
}

当我尝试deserealize JSON对象时,它会抛出错误。当我将string []中的标识符更改为字符串时,它可以工作,但这不是预期的结果。我也尝试了List并且没有用。

1 个答案:

答案 0 :(得分:2)

尝试这样的课程,不要忘记先列出新的列表

public class Info
{
    public string description { get; set; }
    public List<string> tags { get; set; }
}