Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataContractJsonSerializer反序列化列表<;T>;_C#_Json_Rest_Serialization_Deserialization - Fatal编程技术网

C# DataContractJsonSerializer反序列化列表<;T>;

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

我正在为REST WCF服务创建一个通信库。通信类将对象作为参数序列化,并向REST服务URL发出POST请求并等待响应。之后,响应被反序列化并返回。我有一个复合类型作为响应类。这个类有三个字段,其中一个是
列表
,其中
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; } 
}