0
我無法成功將List<StringDictionary>>
的已填充實例從Web API控制器返回到C#
控制檯應用程序。下面是詳細信息...Web Api - 返回字典
的Web API代碼:
[HttpPost]
public async Task<HttpResponseMessage> Get(IEnumerable<long> ids)
{
var results = [assume populated instance of List<StringDictionary>>]
return Request.CreateResponse<List<StringDictionary>>(HttpStatusCode.OK, results);
}
我有下面的客戶端代碼:
using (var httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) })
{
var httpResponse = httpClient.PostAsJsonAsync<long[]>("api/promotions", mockIds).Result;
if (httpResponse.IsSuccessStatusCode)
{
var content = httpResponse.Content.ReadAsAsync<List<StringDictionary>>().Result; ***** DOES NOT WORK ****
}
}
我得到以下錯誤:
{"Cannot create and populate list type System.Collections.Specialized.StringDictionary. Path '[0]', line 1, position 2."}
我在這裏錯過了什麼明顯的事實?
更新 - 有趣的是,如果我將StringDictionary更改爲Dictionary,它的效果很好。