Web API からアプリケーションに文字列値のリストを取得しようとしています。
これは、取得したい Web Api の値の配列です。
public IEnumerable<string> Get()
{
return new string[] { "Item1", "Item2s", "Item3", "Item4", "Item5" };
}
次のコードは、Web API からデータを取得するために使用されます。
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://localhost:1234/api/items");
var items = new List<Items>();
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
// Parse 1 Product from the content
var ItemsSet= JsonConvert.DeserializeObject<dynamic>(content);
var ItemData = new Items
(
(string)ItemsSet[0],
(string)ItemsSet[1],
(string)ItemsSet[2],
(string)ItemsSet[3],
(string)ItemsSet[4]
);
Items.Add(ItemData);
}
ただし、これは string[] の最初の値、つまり「Item1」のみを返します。
これを修正して、配列内のすべての値を取得するにはどうすればよいですか?