Как преобразовать объект класса в массив json в C#?
я вызываю web api через winform, когда передаю данные классу и вызываю функцию, которая показывает мне ошибку.
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Properties.Model.Tenant.TenantListItem[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
Что я уже пробовал:
[DataContract] public class TenantFilter { [DataMember] public string TenantName { get; set; } [DataMember] public long AreaID { get; set; } } // my web api code public async Task<list><tenantlistitem>> GetAllTenant(TenantFilter filter) { var result = new List<tenantlistitem>(); try { var response = await TenantCore.LoadTenantGrid(filter); if (response != null) { result = (List<tenantlistitem>)response; } } catch (System.Exception ex) { } return result; } // calling through winform private async Task<ienumerable><tenantlistitem>> PopulateTenantGridView() { var result = new List<tenantlistitem>(); try { using (var client = new HttpClient()) { var name = txtName.Text; var area = (cmbArea.SelectedValue == null ? 0 : (long)cmbArea.SelectedValue); var tenantfilter = new TenantFilter { TenantName = name, AreaID = area }; var serializedProduct = JsonConvert.SerializeObject(tenantfilter,Formatting.Indented); var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json"); var response = await client.PostAsync("http://localhost:64456/api/Tenant/GetAllTenant/", content); if (response.IsSuccessStatusCode) { var Jsonstring = await response.Content.ReadAsStringAsync(); var tenant = JsonConvert.DeserializeObject<tenantlistitem[]>(Jsonstring).ToList(); if (tenant != null) { result = tenant.Take(100).ToList(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return result; }