0
我想从Web API获取字符串值列表到应用程序中。仅返回字符串数组中的第一项
这是我的网络API值的数组,我想:
public IEnumerable<string> Get()
{
return new string[] { "Item1", "Item2s", "Item3", "Item4", "Item5" };
}
下面的代码被用于从网络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);
}
但这返回获取数据只有字符串[]中的第一个值,即“Item1”。
我该如何解决这个问题,以获得数组中的所有值?
什么是只返回一个项目? 'ItemsSet'是什么?或者它是“物品”? – Verkion
'Items'只返回一个。 – Tester