ERROR
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[RechargePortal.Models.ProviderOperator]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'providers', line 1, position 13.'
List<ProviderOperator> GetProvideOperator(string service)
{
string json = new System.Net.WebClient().DownloadString("URL");
List<ProviderOperator> ob = new List<ProviderOperator>();
ob = JsonConvert.DeserializeObject<List<ProviderOperator>>(json);
ob = ob.Where(x => x.Service.Equals(service)).ToList();
return ob;
}
JSON RESULT
{
"providers":[
{
"provider_id":0,
"provider_name":"PAY2ALL",
"provider_code":"PAY2ALL",
"service_id":10,
"service":"Pay2All Cash",
"provider_image":"",
"status":"Success"
},
{
"provider_id":1,
"provider_name":"AIRTEL",
"provider_code":"A",
"service_id":1,
"service":"Recharge",
"provider_image":"provider_icons\/airtel.png",
"status":"Success"
},
{
"provider_id":2,
"provider_name":"VODAFONE",
"provider_code":"V",
"service_id":1,
"service":"Recharge",
"provider_image":"provider_icons\/vodafone.png",
"status":"Success"
}
]
}
Model
public class ProviderOperator
{
public string Provider_id { get; set; }
public string Provider_name { get; set; }
public string Provider_code { get; set; }
public string Service { get; set; }
public string Provider_image { get; set; }
public string Status { get; set; }
}
