Estoy desarrollando una plataforma nueva la cual consume data desde una api de la SBIF, pero el JSON con la data que me devuelve viene asi
{
"Dolares":
[
{
"Valor": "603,31",
"Fecha": "2018-04-27"
{
]
}
Para consumirla uso httpClient y me arroja un error de "deserialize" eh ocupado varias tecnicas que encontre en por aca pero ninguna me funciona. El error que me retorna la view es este.
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[DetamaticWeb.Models.DolarViewModel]' 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 'Dolares', line 2, position 12.
Alguien seria tan amable para que me indicara como debería consumir esta api por favor?
Controller
string Baseurl = "http://api.sbif.cl/";
public async Task<ActionResult> Index()
{
List<DolarViewModel> EmpInfo = new List<DolarViewModel>();
using (var client = new HttpClient())
{
//Passing service base url
client.BaseAddress = new Uri(Baseurl);
client.DefaultRequestHeaders.Clear();
//Define request data format
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Sending request to find web api REST service resource GetAllEmployees using HttpClient
HttpResponseMessage Res = await client.GetAsync("api");
//Checking the response is successful or not which is sent using HttpClient
if (Res.IsSuccessStatusCode)
{
//Storing the response details recieved from web api
var EmpResponse = Res.Content.ReadAsStringAsync().Result;
//Deserializing the response recieved from web api and storing into the Employee list
EmpInfo = JsonConvert.DeserializeObject<List<DolarViewModel>>(EmpResponse);
}
//returning the employee list to view
return View(EmpInfo);
}
}
Model
public class DolarViewModel
{
public string Valor { get; set; }
public string Fecha { get; set; }
}
Gracias.