RealityDysfunction
RealityDysfunction

Reputation: 2639

JSON ASP.NET Deserialization failing, getting null

From Javascript I send my object via string like so, data is what facebook FQL query returns:

var propData = new Object();
propData.d = data;
var jString = JSON.stringify(propData);
$('#<%=Hidden1.ClientID%>').val(jString);
$('#UpdatePanelTrigger').click();

Then, I receive this string on server side, display this JSON string in a label (which looks ok to me) and try to Deserialize it, code below.

 public class Friends
{
    public IList<Dictionary<string,string>> data {get; set;}
}

protected void UpdateTrigger_Click(object sender, EventArgs e)
{
    JSON_out.Text = Hidden1.Value;
    Friends fbookFriends = new System.Web.Script.Serialization.JavaScriptDerializer().Deserialize<Friends>(JSON_out.Text);
    obj_check.Text = new System.Web.Script.Serialization.JavaScriptSErializer().Serialize(fbookFriends);
    //The result of above line is {"data":null}
}

I don't understand why Deserializer refuses to convert this string to JSON. Any help, would be greatly appreciated. I.N.

PS: If it helps, My JSON string received on server, looks like this: {"d":[{"uid":"XXXXXXXX","name":"Bro Number1","pic_square":"https://fbcdn-profile-a.akamaihd.net/beautiful_avatar.jpg"},{"uid":"XXXXX2","name":...

Upvotes: 0

Views: 180

Answers (1)

I4V
I4V

Reputation: 35363

To be able to deserialize your json string in question your Friends class should be something like that

public class Friend
{
    public string uid { get; set; }
    public string name { get; set; }
    public string pic_square { get; set; }
}

public class Friends
{
    public List<Friend> d { get; set; }
}

But your comments says you have some top level fields like data (//The result of above line is {"data":null})

Upvotes: 1

Related Questions