收到来自SFDC REST Web服务的以下响应(下面的字符串jsonResponse):
{
"responseDataList": [{
"salesforceRecordId": "a00C000000L5DQRIA3",
"recordName": "Computer_Name_2",
"IsSuccess": true,
"errorMessage": null
}]
}
尝试使用ServiceStack.JsonSerializer反序列化:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string jsonResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
ResponseDataList list = JsonSerializer.DeserializeFromString<ResponseDataList>(jsonResponse);
ResponseDataList具有以下结构:
public class ResponseData
{
public string salesforceRecordId { get; set; }
public string recordName { get; set; }
public bool IsSuccess { get; set; }
public string errorMessage { get; set; }
}
public class ResponseDataList
{
List<ResponseData> responseDataList { get; set; }
}
但是,反序列化后ResponseDataList列表为null。我做错了什么,如何正确反序列化?
最佳答案
通过将responseDataList公开,我可以正确地反序列化。
public class ResponseDataList
{
public List<ResponseData> responseDataList { get; set; }
}