C# DataContractJsonSerializer反序列化列表<;T>;
我正在为REST WCF服务创建一个通信库。通信类将对象作为参数序列化,并向REST服务URL发出POST请求并等待响应。之后,响应被反序列化并返回。我有一个复合类型作为响应类。这个类有三个字段,其中一个是C# DataContractJsonSerializer反序列化列表<;T>;,c#,json,rest,serialization,deserialization,C#,Json,Rest,Serialization,Deserialization,我正在为REST WCF服务创建一个通信库。通信类将对象作为参数序列化,并向REST服务URL发出POST请求并等待响应。之后,响应被反序列化并返回。我有一个复合类型作为响应类。这个类有三个字段,其中一个是列表,其中T是另一个类。问题是,对于这两个字段,反序列化过程可以正常工作,但作为列表的字段总是生成一个空列表。Web服务逻辑中没有问题 public class Communicate<RequestType, ResposeType> where ResposeType
列表
,其中T
是另一个类。问题是,对于这两个字段,反序列化过程可以正常工作,但作为列表的字段总是生成一个空列表。Web服务逻辑中没有问题
public class Communicate<RequestType, ResposeType>
where ResposeType : class
where RequestType : class
{
public ResposeType CommunicateSvr(RequestType _parameter, string methodName, string serverIp)
{
DataContractJsonSerializer obj;
WebClient Proxy1 = new WebClient();
Proxy1.Headers["Content-type"] = "application/json";
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer serializerToUplaod = new DataContractJsonSerializer(typeof(RequestType));
serializerToUplaod.WriteObject(ms, _parameter);
byte[] data = Proxy1.UploadData(serverIp + methodName, "POST", ms.ToArray());
Stream stream = new MemoryStream(data);
obj = new DataContractJsonSerializer(typeof(ResposeType));
ResposeType _respons = obj.ReadObject(stream) as ResposeType;
return _respons;
}
}
班级反应
public class GetTransactionsPENALTY
{
public bool test1 { get; set; }
public int test2 { get; set; }
public int test3 { get; set; }
public int test4 { get; set; }
public List<MinPenaltyTransaction> list { get; set; }
}
public类getTransactionsPanalty
{
公共bool test1{get;set;}
公共int test2{get;set;}
公共int test3{get;set;}
公共int test4{get;set;}
公共列表{get;set;}
}
我做错了什么或者我应该改变什么?
提前感谢您说列表的类型是
T
,但它的类型是MinPenaltyTransaction
。您能提供MinPenaltyTransaction
类吗?为了给我们提供更多帮助,请分享MinPenaltyTransaction
类和响应JSON。否则,请查看以确保MinPenaltyTransaction
是受支持的类型。
public class GetTransactionsPENALTY
{
public bool test1 { get; set; }
public int test2 { get; set; }
public int test3 { get; set; }
public int test4 { get; set; }
public List<MinPenaltyTransaction> list { get; set; }
}