Hi,
I am trying to deserialize JSON string to .NET object in a plugin.I am using DataContractJsonSerializer as JavaScriptSerializer has security issues. But , still I am facing below error.
Error Message :
Type 'UpdateOpportunitiesFromIntegration.jsondataclass' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
Code :
string jsonobject = entity.Attributes["ae_operativeintegrationobject"].ToString();
using (System.IO.MemoryStream DeserializeStream = new System.IO.MemoryStream())
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(jsondataclass));
System.IO.StreamWriter writer = new System.IO.StreamWriter(DeserializeStream);
writer.Write(jsonobject);
writer.Flush();
DeserializeStream.Position = 0;
jsondataclass deserializeobj = (jsondataclass)serializer.ReadObject(DeserializeStream);
}
Class file added to solution :
class jsondataclass
{
public string SalesOrderId { get; set; }
public string SalesOrderName { get; set; }
public string SalesOrderStage { get; set; }
public string OrderStartDate { get; set; }
public string OrderEndDate { get; set; }
public string TotalOrderValue { get; set; }
}
*This post is locked for comments