
Hi friends,
Please find the below code for Calling weather web api in C# console app.
Nuget Package: Newtonsoft.Json;
Thanks,
Bharath
If it is useful Hit"Like".
======================================================
using Newtonsoft.Json.Linq;
using System;
using System.Net;
namespace Calling_External_API
{
class Program
{
static void Main(string[] args)
{
string results = "";
string city;
Console.Write("Enter a city- ");
city = Console.ReadLine();
using (WebClient wc = new WebClient())
{
string searchtext = "select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text='" + city + "') and u='c'";
results = wc.DownloadString("https://query.yahooapis.com/v1/public/yql?q=" + searchtext + "&format=json");
dynamic jo = JObject.Parse(results);
var items = jo.query.results.channel.item.condition;
var code = items.code;
var temp = items.temp;
var text = items.text;
var date= items.date;
Console.WriteLine("\n Temperature in "+city +" is " + temp + "°C");
Console.WriteLine("\n Today" + " - " + text);
Console.Read();
}
}
}
=====================================================
output:
*This post is locked for comments
I have the same question (0)Thanks for the very informative post.
This would be really organized when you start writing a blog post: community.dynamics.com/.../136.request-a-new-blog-or-blog-to-syndicate
Here, we will post our questions/problems to get answers/solutions from fellow community members.