Created
February 25, 2013 05:59
-
-
Save SleepyCrat/5028048 to your computer and use it in GitHub Desktop.
This file is an example of how to make a call to the YQL service.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Net; | |
using System.Web; | |
using Newtonsoft.Json.Linq; | |
namespace YQLExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
StringBuilder theWebAddress = new StringBuilder(); | |
theWebAddress.Append("http://query.yahooapis.com/v1/public/yql?"); | |
theWebAddress.Append("q=" + System.Web.HttpUtility.UrlEncode("select * from local.search where location='Nashville ,TN' and query='Fast Food'")); | |
theWebAddress.Append("&format=json"); | |
theWebAddress.Append("&diagnostics=false"); | |
string results = ""; | |
using (WebClient wc = new WebClient()) | |
{ | |
results = wc.DownloadString(theWebAddress.ToString()); | |
} | |
JObject dataObject = JObject.Parse(results); | |
JArray jsonArray = (JArray)dataObject["query"]["results"]["Result"]; | |
foreach (var locationResult in jsonArray) | |
{ | |
Console.WriteLine("Name:{0}", locationResult["Title"]); | |
Console.WriteLine("Address:{0}", locationResult["Address"]); | |
Console.WriteLine("Longitude:{0}", locationResult["Longitude"]); | |
Console.WriteLine("Latitude:{0}", locationResult["Latitude"]); | |
Console.WriteLine(Environment.NewLine); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment