I´m trying to get single value out of an object array and display it for now inside paragraph tag on my index page.
In my HomeController I have done this
public ActionResult Index()
{
WebClient client2 = new WebClient();
Stream stream = client2.OpenRead("http://localhost/ARN/weatherAPI.json");
StreamReader reader = new StreamReader(stream);
Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine());
// instead of WriteLine, 2 or 3 lines of code here using WebClient to download the file
var weatherString = (string)jObject["weather"][0]["main"];
stream.Close();
return View();
I started by creating a new project in Console Application to test it and I ran this lines of code but used Console.Writeline(weatherString) and it gave me exactly the value I needed in the console but now I'm facing the problem to try to show it on the index page with the ASP.NET MVC
Since this piece of code is in my HomeController and my Index.cshtml is elsewhere, is there an easy way for me to output the weatherString variable as an simple text on my index page?
The JSON looks like this:
"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}]
So I wan't "Rain" to be outputted on my webpage.
ViewBagor the model