Skip to content

Instantly share code, notes, and snippets.

@waema
Forked from amithgeorge/gist:973457
Created May 15, 2011 20:40
Show Gist options
  • Save waema/973510 to your computer and use it in GitHub Desktop.
Save waema/973510 to your computer and use it in GitHub Desktop.
/*
Rewrite the sdata class as follows.
*/
public class sdata
{
public string id { get; set; }
public sfrom from { get; set; }
public string message { get; set; }
public string updated_time { get; set; }
public likedatacollection likes { get; set; }
}
/*
add the likedatacollection class
*/
public class likedatacollection
{ public likedatacollection (){data = new List<likesdata>(); }
public List<likesdata> data { get; set; }
}
/*
The other classes remain as they are
*/
public class Allstatus
{
public List<sdata> data { get; set; }
//public scpaging paging { get; set; }
}
public class likesdata
{ public likesdata(){id=name=":|:";}}
public string id { get; set; }
public string name { get; set; }
}
public class sfrom
{
public string name { get; set; }
public string category { get; set; }
public string id { get; set; }
}
public class Request
{
public string requestFBData(string action)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(action);
req.Timeout = 60000;
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string results = sr.ReadToEnd();
sr.Close();
return results;
}
}
var result = new Request().requestFBData("https://graph.facebook.com/platform/statuses?access_token=" + "202929493078068|886e4149cac7be0fc12e2d4b.0-100002424609963|a9CMw51PYEW3kj4xw77JyEJoRrI");
var deserializedAllStatus = javaScriptSerializer.Deserialize<Allstatus>(result);
foreach (sdata sd in deserializedAllStatus.data)
foreach (likesdata ld in sd.likes.data)
Console.WriteLine(ld.id + ld.name);
@amithgeorge
Copy link

Could you also show what the variable result contains? What is the actual json returned by the server? Please replace any sensitive/personal info with dummy info.

@waema
Copy link
Author

waema commented May 16, 2011

the key is dummy.. i will delete it anyway soon. The returned info is from https://graph.facebook.com/platform/statuses?access_token=< access_token here > This brings a nullreference on the likesdata. I don't know every thing from code looks okay.

@waema
Copy link
Author

waema commented May 16, 2011

I have tried both using system.web.script.serialization and using JSON.net. Both bring null reference.. After initializing the likesdata using contructors.

@waema
Copy link
Author

waema commented May 19, 2011

Adding a constructor in the sdata.. solved it..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment