Sunday, February 8, 2015

Complex Json deserialization C# (class is not supported for deserialization of an array)


I am trying to deserialization array bellow this way.
This is my json file.
[
   [
      {
         "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"
      }
   ]
]

Bellow my candidate Resume class
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; }

        }

I have bind this "WebScrappingCandidate" class this bellow way.
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
                List> myobj = jsSerializer.Deserialize>>(description);

                foreach (List listCandidateResume in myobj)
                {
                    foreach (CandidateResume candidateResume in listCandidateResume)
                    {
                        WebScrappingCandidate webScrappingCandidate = new WebScrappingCandidate();
                        webScrappingCandidate.FullName = candidateResume.name;
                        webScrappingCandidate.ResumeUrl = candidateResume.url;
                        webScrappingCandidate.Summary = candidateResume.summary;
                        webScrappingCandidate.PositionName = candidateResume.role;
                        webScrappingCandidate.Compensation = candidateResume.compensation;
                        webScrappingCandidate.Education = candidateResume.education;
                        webScrappingCandidate.Skills = candidateResume.expertise;
                        webScrappingCandidate.YearsOfExperience = candidateResume.years;
                        webScrappingCandidate.Relocation = candidateResume.relocation;                        
                        webScrappingCandidate.ResumeText = candidateResume.resume;                                                                  
                    }                                       
                }   

Happy Programming :)

1 comment:

  1. ASP.NET MVC as compared to the runtime environment of ASP.NET offers you a completely different experience of using Web Forms.

    Hire ASP.Net MVC developer in India

    ReplyDelete