2013-10-24 47 views
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」。

我該如何解決這個問題,以獲得數組中的所有值?

+0

什麼是隻返回一個項目? 'ItemsSet'是什麼?或者它是「物品」? – Verkion

+0

'Items'只返回一個。 – Tester

回答

0

我認爲.. 將itemset作爲數組使用它作爲一個變量。 var[] itemset

相關問題