unfortunately I have zero experience in C#, but I need to create JSON source in SSIS.
I'm trying to download JSON, deserialize and save it to list:
public override void CreateNewOutputRows()
{
JavaScriptSerializer serialize = new JavaScriptSerializer();
var employees = new List<Employees>();
employees = serialize.Deserialize<List<Employees>>(json);
foreach (var record in employees)
{
Output0Buffer.AddRow();
Output0Buffer.FirstName = record.FirstName;
Output0Buffer.EmailId = record.EmailID;
Output0Buffer.Profile = record.Profile;
Output0Buffer.EmployeeIDInternal = record.EmployeeIDInternal;
Output0Buffer.LastName = record.LastName;
}
}
Employees is:
public class Employees
{
public string FirstName { get; set; }
public string EmailID { get; set; }
public string Profile { get; set; }
public string EmployeeIDInternal { get; set; }
public string LastName { get; set; }
}
But it fails with following error:
System.Reflection.AmbiguousMatchException
HResult=0x8000211D
Message=Ambiguous match found.
Source=mscorlib
UPD: @OlivierJacot-Descombes I can't show you original json, but I tried approach from JavaScriptSerializer method documentation by creating json from serializer:
var RegisteredUsers = new List<Employees>();
RegisteredUsers.Add(new Employees() { FirstName = "Name1", EmailID = "abc@gmail.com", Profile = "DB", EmployeeIDInternal = "123", LastName = "Surname1" });
RegisteredUsers.Add(new Employees() { FirstName = "Name2", EmailID = "abc1@gmail.com", Profile = "DB1", EmployeeIDInternal = "1234", LastName = "Surname2" });
RegisteredUsers.Add(new Employees() { FirstName = "Name3", EmailID = "abc234@gmail.com", Profile = "SQL", EmployeeIDInternal = "77", LastName = "Surname3" });
RegisteredUsers.Add(new Employees() { FirstName = "Name4", EmailID = "absdfsc@gmail.com", Profile = "", EmployeeIDInternal = "555", LastName = "Surname4" });
var serializer = new JavaScriptSerializer();
var serializedResult = serializer.Serialize(RegisteredUsers);
var employees = serializer.Deserialize<List<Employees>>(serializedResult);
it generates following json text (the original is unformatted on a single line of text):
[
{
"modifiedTime":null,
"Addedtime":null,
"FirstName":"Name1",
"EmailID":"abc@gmail.com",
"Photo":null,
"HRSpecialist":null,
"AddedBy":null,
"Gender":null,
"ApprovalStatus":null,
"Profile":"DB",
"CarNumberPlate":null,
"recordId":null,
"ModifiedBy":null,
"Department":null,
"EmployeeIDInternal":"123",
"Modifiedtime":null,
"ownerName":null,
"createdTime":null,
"TechnicalLevel":null,
"Room":null,
"Tags":null,
"Photo_downloadUrl":null,
"ReportingTo":null,
"FirstProject":null,
"Designation":null,
"IM":null,
"WorkLocation":null,
"ownerID":null,
"MaritalStatus":null,
"DateofJoining":null,
"IMServiceProvider":null,
"CompetenceLead":null,
"DateofBirth":null,
"LastName":"Surname1",
"EmployeeID":null,
"MobilePhone":null,
"Expertise":null,
"Location":null
},
{
"modifiedTime":null,
"Addedtime":null,
"FirstName":"Name2",
"EmailID":"abc1@gmail.com",
"Photo":null,
"HRSpecialist":null,
"AddedBy":null,
"Gender":null,
"ApprovalStatus":null,
"Profile":"DB1",
"CarNumberPlate":null,
"recordId":null,
"ModifiedBy":null,
"Department":null,
"EmployeeIDInternal":"1234",
"Modifiedtime":null,
"ownerName":null,
"createdTime":null,
"TechnicalLevel":null,
"Room":null,
"Tags":null,
"Photo_downloadUrl":null,
"ReportingTo":null,
"FirstProject":null,
"Designation":null,
"IM":null,
"WorkLocation":null,
"ownerID":null,
"MaritalStatus":null,
"DateofJoining":null,
"IMServiceProvider":null,
"CompetenceLead":null,
"DateofBirth":null,
"LastName":"Surname2",
"EmployeeID":null,
"MobilePhone":null,
"Expertise":null,
"Location":null
},
{
"modifiedTime":null,
"Addedtime":null,
"FirstName":"Name3",
"EmailID":"abc234@gmail.com",
"Photo":null,
"HRSpecialist":null,
"AddedBy":null,
"Gender":null,
"ApprovalStatus":null,
"Profile":"SQL",
"CarNumberPlate":null,
"recordId":null,
"ModifiedBy":null,
"Department":null,
"EmployeeIDInternal":"77",
"Modifiedtime":null,
"ownerName":null,
"createdTime":null,
"TechnicalLevel":null,
"Room":null,
"Tags":null,
"Photo_downloadUrl":null,
"ReportingTo":null,
"FirstProject":null,
"Designation":null,
"IM":null,
"WorkLocation":null,
"ownerID":null,
"MaritalStatus":null,
"DateofJoining":null,
"IMServiceProvider":null,
"CompetenceLead":null,
"DateofBirth":null,
"LastName":"Surname3",
"EmployeeID":null,
"MobilePhone":null,
"Expertise":null,
"Location":null
},
{
"modifiedTime":null,
"Addedtime":null,
"FirstName":"Name4",
"EmailID":"absdfsc@gmail.com",
"Photo":null,
"HRSpecialist":null,
"AddedBy":null,
"Gender":null,
"ApprovalStatus":null,
"Profile":"",
"CarNumberPlate":null,
"recordId":null,
"ModifiedBy":null,
"Department":null,
"EmployeeIDInternal":"555",
"Modifiedtime":null,
"ownerName":null,
"createdTime":null,
"TechnicalLevel":null,
"Room":null,
"Tags":null,
"Photo_downloadUrl":null,
"ReportingTo":null,
"FirstProject":null,
"Designation":null,
"IM":null,
"WorkLocation":null,
"ownerID":null,
"MaritalStatus":null,
"DateofJoining":null,
"IMServiceProvider":null,
"CompetenceLead":null,
"DateofBirth":null,
"LastName":"Surname4",
"EmployeeID":null,
"MobilePhone":null,
"Expertise":null,
"Location":null
}
]
The Employees
class seems to have many more properties or fields than you are showing us.
In your JSON text I see two entries per record that are similar:
"modifiedTime":null, field #1
"Modifiedtime":null, field #16
They are only distinguished by the letter case. They are most probably the origin of the System.Reflection.AmbiguousMatchException
. Either rename one of them of remove one of them.
One is possibly a property while the other one is a field. See: How to exclude property from Json Serialization
User contributions licensed under CC BY-SA 3.0