Click here to Skip to main content
13,191,331 members (76,171 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 26 Mar 2012

Facebook registration - JSON object to C# object

, 26 Mar 2012
Rate this:
Please Sign up or sign in to vote.


A way to recieve a facebook user registration and split it down to parse it into a C# object.

Using the code

In your HTML page:

More info:

<iframe src="

client_id=[YOUR API]&

redirect_uri=[YOUR WEBSITE]/GetRegistration&









In your Controller:

public JsonResult GetRegistration()


IDictionary<string,object> dict = DecodePayload(Request["signed_request"].Split('.')[1]);

JavaScriptSerializer serializer = new JavaScriptSerializer();

object reg = (object)dict["registration"];

string registrationJson = serializer.Serialize(reg);

IDictionary<string, object> newRegister = (IDictionary<string, object>)serializer.DeserializeObject(registrationJson);

object loc = (object)newRegister["location"];

string locationJson = serializer.Serialize(loc);

IDictionary<string, object> newLocation = (IDictionary<string, object>)serializer.DeserializeObject(locationJson);

string UserID = (string)dict["user_id"];

string namn = newRegister["name"].ToString().Replace("\"", "");

string birthday = newRegister["birthday"].ToString().Replace("\"", "");

string gender = newRegister["gender"].ToString().Replace("\"", "");

string location = newLocation["name"].ToString().Replace("\"", "");

string email = newRegister["email"].ToString().Replace("\"", "");

string password = newRegister["password"].ToString().Replace("\"", "");

string ImageURL = "" + UserID + "/picture&type=large";

//Now when we have the strings, we can create our own registration model, or put it in our database... 

return Json("something", JsonRequestBehavior.AllowGet);


I got the decoding method from : Pavel Chuchuva @

public IDictionary<string, object> DecodePayload(string payload)
string base64 = payload.PadRight(payload.Length + (4 - payload.Length % 4) % 4, '=')

.Replace('-', '+').Replace('_', '/');

string json = Encoding.UTF8.GetString(Convert.FromBase64String(base64));

return (IDictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);


Good luck!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sweden Sweden
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

QuestionWeb Forms? Pin
Madde8822-Apr-13 4:21
memberMadde8822-Apr-13 4:21 
QuestionThanks Pin
Mellita27-Mar-12 19:45
memberMellita27-Mar-12 19:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171017.1 | Last Updated 26 Mar 2012
Article Copyright 2012 by henke164
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid