对于数组的反序列化,不支持CandidateResume'类

时间:2015-02-06 16:30:58

标签: c# arrays json asp.net-mvc-4

我正在尝试以这种方式反序列化数组,但我收到了这个错误。

JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
var myobj = jsSerializer.Deserialize<CandidateResume[]>(json);

这是我的json文件

[
   [
      {
         "name":"Riaz Kabir",
         "url":"https://recruit.theladders.com/resumeviewer?jobseekerId=01-sid-BDLBKUPMIL6HGZ22MOAJJIWYGE",
         "summary":"ASP.NET MVC Developer Hewlett-Packard (HP) (1/2013-Present) Location: Schenectady, NY Compensation: $50k+ Previous Titles/Companies: 2016 ►",
         "role":"ASP.NET MVC Developer at Hewlett-Packard (HP)",
         "compensation":"$50k+",
         "education":"BS, Computer Science and Engineering, Asian University of Bangladesh",
         "expertise":"Databases , IT Consulting , Software Development , Front End Development",
         "years":"Less than 5",
         "relocation":"Schenectady, NY Within 1000 miles of 12305 Would need to relocate here",
         "resume":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAP",
         "resumeExtension":"doc",
         "resumeMimeType":"application/msword"
      }
   ]
]

贝娄我的候选人简历班

public class CandidateResume
        {

            public string name { get; set; }
            public string url { get; set; }
            public string summary { get; set; }
            public string role { get; set; }
            public string compensation { get; set; }
            public string education { get; set; }
            public string expertise { get; set; }
            public string years { get; set; }
            public string relocation { get; set; }
            public string resume { get; set; }
            public string resumeExtension { get; set; }
            public string resumeMimeType { get; set; }

        }

错误消息:CandidateResume'不支持反序列化数组。

2 个答案:

答案 0 :(得分:2)

您的JSON是列表的列表。考虑错误CandidateResume is not supported for deserialization of an array.它试图将数组反序列化为CandidateResume对象。

而是尝试:

var myobj = jsSerializer.Deserialize<List<List<CandidateResume>>>(json);

或者将您的JSON更改为不是列表列表。

答案 1 :(得分:0)

在json你有额外的&#39; [&#39;和&#39;]&#39;。只需删除它们。 或者,如果不可接受,您可以尝试

var myobj = jsSerializer.Deserialize<CandidateResume[][]>(json);