0

I am Fetching the story tags of a facebook newsfeed by posting to garph api as below and am getting the json response object the contents of which is as follows

  {
 "from": {
  "category": "Recreation/sports website",
  "name": "Cricinfo",
  "id": "18429207554"
 },
"id": "18429207554_10152399273812555",
"created_time": "2014-10-11T04:48:21+0000"
}

now i want to parse this object in c# to get the "name" field value and "id" field value...Can someone please guide me as to how to parse the json object and get the values

 Newsfeed_Id = jsonObj1.Data([i]).id
                            Dim requestgetTags As WebRequest = _
          WebRequest.Create("https://graph.facebook.com/v2.1/" & Newsfeed_Id & "?fields=from,story_tags&access_token=" & _Obj.AccessToken & "")

                            requestgetTags.Credentials = CredentialCache.DefaultCredentials
                            Dim responsegetTags As WebResponse = requestgetTags.GetResponse()
                            Console.WriteLine(CType(responsegetTags, HttpWebResponse).StatusDescription)
                            Dim dataStreamgetTags As Stream = responsegetTags.GetResponseStream()
                            Dim readergetTags As New StreamReader(dataStreamgetTags)
                            Dim responseFromServergetTags As String = readergetTags.ReadToEnd()
  • possible duplicate of [How to parse json in C#?](http://stackoverflow.com/questions/6620165/how-to-parse-json-in-c) – Brian Rogers Oct 13 '14 at 14:50

1 Answers1

0

First of all, your code example is on VB, not C#. But if you still want to parse json in C#, here is an example of how you can do it.

var parsedResponse = JsonConvert.DeserializeObject<NewsFeed>(jsonResponse);

To make it work you should use Newtonsoft.Json dll and specify NewsFeed class as follows:

    public class NewsFeed
    {
      public string Id;
      public string CreatedTime;
      public Tag From;
    }

    public class Tag
    {
      [JsonConstructor]
      public NewsFeed(string category, string name, string id)
      {
         Category = category;
         Name = name;
         Id = id
      }
      public string Category;
      public string Name;
      public string Id;
    }
ZuoLi
  • 383
  • 2
  • 14