Parsing Json data from facebook in c#

When we use Facebook social authentication process ( I mean Login by Facebook) after successful authentication from Facebook we get user information in Json format. Now we have situation to how to deserialize json format data. For this purpose we have several option for deserialize json data. Either we can use some third party tool to parse json data or we can use JavaScriptSerializer.

Option Can we have when we think in terms of third party tool:
1)parsing JSon using JSon.net
2)JSON Checker
3)JAYROCK

So How we can achieve Json parsing without ant third party tool:

Json Data which We have to parse:

var responseText = @"{
"id":"100000891948867",
"name":"Nishant Sharma",
"first_name":"Nishant",
"last_name":"Sharma",
"link":"https:\/\/www.facebook.com\/profile.php?id=100000891948867",
"gender":"male",
"email":"nihantanu2010\u0040gmail.com",
"timezone":5.5,
"locale":"en_US",
"verified":true,
"updated_time":"2013-06-10T07:56:39+0000"
}"

So For above json format data you can create Class I have created


public class UserInformation
{
public string id { get; set; }
public string name { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string link { get; set; }
public string gender { get; set; }
public string email { get; set; }
public double timezone { get; set; }
public string locale { get; set; }
public bool verified { get; set; }
public string updated_time { get; set; }
}

User

Now use JavaScriptSerializer

JavaScriptSerializer objJavaScriptSerializer = new JavaScriptSerializer();
UserInformationparsedData = objJavaScriptSerializer.Deserialize(responseText);

It will successfully parse data to UserInformation object.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s