1

Closed

FastJson Deserialize

description

Hi,

I am trying to deserialize using fastjson but getting error. Please find the below code

Company company = GetData();
string json = JSON.ToJSON(company);
var a = JSON.ToObject<Company>(json);
Failed to fast create instance for type 'Serialization.Program+Company' from assembly 'Serialization.Program+Company, Serialization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'


Below are the Company class structure

public class Company
    {
        public string Title { get; set; }
        public List<Program.Employee> Employees { get; set; } 
    }

    public class Employee
    {
        public string Name { get; set; }
        public EmployeeType Employeetype { get; set; }
    }

    public enum EmployeeType
    {
        CEO,
        Developer
    }
public static Company GetData()
    {
        return new Company()
        {
            Title = "Tesco HSC",
            Employees = new List<Employee>()
            {
                new Employee() {Name = "Mark CEO", Employeetype = EmployeeType.CEO},
                new Employee() {Name = "Praveen", Employeetype = EmployeeType.Developer},
                new Employee() {Name = "Yash", Employeetype = EmployeeType.Developer}
            }
        };
    }
Closed Jul 15, 2016 at 9:43 AM by MGholam

comments

MGholam wrote Jul 15, 2016 at 9:43 AM

Make the static class Program public, or put the Company out side of the Program class.