Json
文字列をデシリアライズしようとしています。私のデシリアライゼーションは まで動作しOrderData
ます。私が逆シリアル化するOrderData
と、常に表示さnull
れSourceData
なくなります。エラーも発生していません。これを解決するための提案はありますか?
string jsonString = @"
{
""RequestId"":514106,
""Warning"":[],
""CustomerData"": {
""Email"":""abc@abc.com"",
""FullName"":""OrTguOfE"",
""OrderData"":[{
""OrderId"":""123"",
""SourceId"":""0"",
""SourceData"": [{
""SourceDescription"":""This is sourcedesc"",
""ProductName"":""xyzabc""
}]
}]
}
}";
私の逆シリアル化コードは次のとおりです。
RecordInfo records= Deserialize<RecordInfo>(jsonString);
private static T Deserialize<T>(string jsonString)
{
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
{
var serializer = new DataContractJsonSerializer(typeof(T));
return (T)serializer.ReadObject(ms);
}
}
これが私が使用するデータコントラクトです
[DataContract]
public class RecordInfo
{
[DataMember(Name = "RequestId")]
public string RequestId { get; set; }
[DataMember(Name = "Warning")]
public string Warning { get; set; }
[DataMember(Name = "CustomerData")]
public CustomerData CustomerData { get; set; }
}
[DataContract]
public class CustomerData
{
[DataMember(Name = "Email")]
public string RequestId { get; set; }
[DataMember(Name = "FullName")]
public string FullName { get; set; }
[DataMember(Name = "OrderData")]
public OrderData OrderData { get; set; }
}
[DataContract]
public class OrderData
{
[DataMember(Name = "OrderId")]
public string OrderId { get; set; }
[DataMember(Name = "SourceId")]
public string SourceId { get; set; }
[DataMember(Name = "SourceData")]
public SourceData SourceData { get; set; }
}
[DataContract]
public class SourceData
{
[DataMember(Name = "SourceDescription")]
public string SourceDescription { get; set; }
[DataMember(Name = "ProductName")]
public string ProductName { get; set; }
}