如何从数据库中获取数组中的数据?

时间:2019-03-30 11:41:10

标签: c# xamarin.forms

我想将数据从数据库获取到数组中,但是我被困在这里需要解决此问题

public class FeaturedItemList
{
  public List<PagingProduct> products { get; set; }
}

public class PagingProduct
{
  public string name { get; set; }
}

public class PagingProductRepository
{
  public ObservableCollection<PagingProduct> pagingProducts { get; set; }
  public FeaturedItemList products;

  public PagingProductRepository() { }

  public async void GetData()
  {
    var httpClient = new HttpClient();

    var json = await httpClient.GetStringAsync("http://orangepotato.rjcpacking.com/index.php?route=api/login/getFeaturedProducts");

    products = JsonConvert.DeserializeObject<FeaturedItemList>(json);                                
 }

 internal string[] names= new string[]
 {
    // Here i want to get data   
 };

如果我使用这样的静态数据

internal string names;
{
   "1500 Reviews", "1000 Reviews", "1200 Reviews", "1400 Reviews", "1600 Reviews",
   "1700 Reviews", "1800 Reviews", "1900 Reviews", "2500 Reviews", "1500 Reviews",
};

它工作正常,但是我需要从数据库中获取数据

1 个答案:

答案 0 :(得分:0)

类似:

var featuredItemList = JsonConvert.DeserializeObject<FeaturedItemList>(json);
names = featuredItemList.products.Select( p=> p.name ).ToArray();