Help me find the error, why does not it work? I was guided by this (https://www.newtonsoft.com/json/help/html/DeserializeWithLinq.htm) documentation.
This is my controller:
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
// Example JSON
var webClient = new WebClient();
var json = webClient.DownloadString(@"http://www.json-generator.com/api/json/get/ckJzNVJRIO?indent=2");
JArray flypoolArray = JArray.Parse(json);
IList<flypool> blogPosts = flypoolArray.Select(p => new flypool
{
hashRate = (string)p["data"]["hashRate"],
blocksPerHour = (string)p["data"]["blocksPerHour"],
priceUsd = (string)p["data"]["priceUsd"],
priceBtc = (string)p["data"]["priceBtc"],
}).ToList();
return View(blogPosts);
}
}
Classes flypool.cs
namespace WebApplicationParse.Models
{
public class flypool
{
public string hashRate { get; set; }
public string blocksPerHour { get; set; }
public string priceUsd { get; set; }
public string priceBtc { get; set; }
}
}
View Index.cshtml
@model WebApplicationParse.Models.flypool
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div class="container">
<div class="col-md-6 col-md-offset-3">
<ul>
<li>@Model.hashRate</li>
</ul>
</div>
</div>
Shows here this error "Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1."
Help me please.