I'm looking for a simple example of calling a feed from a url and then looping through the data pulling the values out in C#.
I'm managed to get the feed data into a string variable like this. I've looked at the newtonsoft.Json dll but can't find a simple example of pulling the data out. The data isn't complex and i've added it to the bottom.
so basically _feedData now contains my JSON data I somehow like to convert it into a JSON object then foreach it pulling the values out.
static void Main(string[] args)
{
string _feedData = GetJSONFeed();
}
public static string GetJSONFeed()
{
string formattedUri = "http://www.myJsonFeed.com/blah.json";
HttpWebRequest webRequest = GetWebRequest(formattedUri);
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
string jsonResponse = string.Empty;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
jsonResponse = sr.ReadToEnd();
}
return jsonResponse;
}
private static HttpWebRequest GetWebRequest(string formattedUri)
{
// Create the request’s URI.
Uri serviceUri = new Uri(formattedUri, UriKind.Absolute);
// Return the HttpWebRequest.
return (HttpWebRequest)System.Net.WebRequest.Create(serviceUri);
}
my JSON data is like this:
[
{
"id": "9448",
"title": "title title title",
"fulltext": "main body text",
"url": "http://www.flikr.co.uk?id=23432"
},
{
"id": "9448",
"title": "title title title",
"fulltext": "main body text",
"url": "http://www.flikr.co.uk?id=23432"
}
]
thanks for any help. Rob