I am trying to get facebook wall but I am having issues with JSON Nested structure.
following is my code so far
var wall = (JsonObject)fb.Get("me/feed");
List<FBWall> myWall = new List<FBWall>();
foreach (var obj in (JsonArray)wall["data"])
{
FBWall myWall = new Wall();
myWall.Id = (string)(((JsonObject)obj)["id"]);
}
actual string in wall is coming something like this
{"data":[{"id":"576376893_10150590188751894","from":{"name":"Afnan Bashir","id":"576376893"},"story":"\"how are you man??? \" on Xain Ul-Abiddin's timeline."........ and so on
now I have got data but when i do (as it should come like this because main file contains other json arrays)
(((JsonObject)obj)["from"]) I get {"name":"Afnan Bashir","id":"576376893"}
now how would you write in foreach to get everything without going to another foreach. I was thinking for some way may be with Linq
It’s always hard to cast an object like FbWall to the returned results of the Graph API. As much as I like type safety and being able to see compile-time errors, it was too much of a pain in the butt to convert the dynamic data over to a type.
So I’ve become adjusted to using
dynamic(if you’re using 4.0).If you’re not using 4.0, then you can continue to use
wall["data][0]["from"][0]["name"]to get at values of the object returned.I really do love living around the warmth and snuggliness of type safety, and I kicked and screamed about having to live down this unknown and uncomfortable road. It will be all right, just “bite the bullet” and “get ‘er done”.