をデシリアライズ私は(のHttpClientのようなものです)RestSharpコールを持っていると私は、このエラー{"Cannot create an instance of an interface."}
RestSharpは手動
ウェブAPIメソッドからのデータを返す必要が
私のコードは次のようになります。
public List<Interest> GetInterests()
{
var request = new RestRequest(apiPath + "GetInterests", Method.GET) { RequestFormat = DataFormat.Json };
var response = Client.Execute<List<Interest>>(request);
return response.Data;
}
マイresponse.Contentは以下を示しています。
この問題は、DATAがレスポンスオブジェクトのContentプロパティにJSONとして存在するように見えます。私はそこから手動でデシリアライズすることができます。しかし、以前はDataプロパティに自動的にデシリアライズしていましたが、今起こっていることはわかりません。
jsonを手動でデシリアライズすると動作しますが、なぜこれを行う必要がありますか?
List<Interest> results = JsonConvert.DeserializeObject<List<Interest>>(response.Content);
応答:
"StatusCode: OK, Content-Type: application/json; charset=utf-8, Content-Length: 5597)"
JSONコードは、私が手動でJSONをデシリアライズした場合、それが動作
[
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":1,
"InterestName":"Nursing",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":2,
"InterestName":"Creating/Supporting Networks of Community Partners",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":3,
"InterestName":"Epidemiology",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":4,
"InterestName":"Maternal",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":5,
"InterestName":"Healthcare for the Homeless",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":6,
"InterestName":"HIV/AIDS, STD",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":7,
"InterestName":"Nutrition",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":8,
"InterestName":"Physical Activity",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":9,
"InterestName":"Oral Health",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":10,
"InterestName":"Public Health Communication",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":11,
"InterestName":"Emergency Preparedness and Response",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":12,
"InterestName":"Public Health Policy",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":13,
"InterestName":"Tuberculosis",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":14,
"InterestName":"Teen Pregnancy Prevention",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":15,
"InterestName":"Vital Registration",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":16,
"InterestName":"Chronic Disease",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":17,
"InterestName":"Finance & Management",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":18,
"InterestName":"Quality Improvement",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":19,
"InterestName":"Healthy Community Design",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":20,
"InterestName":"Behavioral Health and Healthcare Integration",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":21,
"InterestName":"Rx Drug Misuse and Abuse",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":22,
"InterestName":"Injury Prevention",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":23,
"InterestName":"School Health",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":24,
"InterestName":"Worksite Wellness",
"AddDate":"2016-07-01T17:03:21.61",
"ModDate":"2016-07-01T17:03:21.64",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
},
{
"InternInterests":[
],
"OfficeInterests":[
],
"InterestId":25,
"InterestName":"Access to Healthy Foods",
"AddDate":"2016-08-03T08:10:45.4",
"ModDate":"2016-08-03T08:10:45.4",
"AddUser":"System",
"ModUser":"System",
"IsDeleted":false
}
]
を返された - しかし、なぜ私はこれを行う必要があります?
List<Interest> results = JsonConvert.DeserializeObject<List<Interest>>(response.Content);
@Ed thxはいjsonが厄介でした –