我有一项将数据发布到URL并监听响应的服务。 这是服务电话
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = null;
response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, encode, true);
string strResponse = reader.ReadToEnd();
它返回的字符串响应是
"{"TransactionConfirmationWrapedResult":"{\"ResultCode\":\"1\",\"ResultDesc\":\"Failed -\",\"ThirdPartyTransID\":\"\"}"}"
我想将此结果映射到这样的类;
public class M2PDto
{
[DataMember(Name = "TransactionConfirmationWrapedResult")]
public M2P2Dto WrapedResult { get; set; }
}
public class M2P2Dto
{
[DataMember(Name = "ResultCode")]
public string ResultCode { get; set; }
[DataMember(Name = "ResultDesc")]
public string ResultDesc { get; set; }
[DataMember(Name = "ThirdPartyTransID")]
public string ThirdPartyTransID { get; set; }
}
这是我的反序列化代码
M2PDto m2P = JsonConvert.DeserializeObject<M2PDto>(strResponse);
我似乎无法弄清楚如何反序列化,通过将null传递给m2P