I`m trying to perform a linq query in a friends JsonArray using Facebook C# SDK. So, i try:
var facebook = new FacebookWebClient();
dynamic facebookFriends = facebook.Get("me/friends");
JsonArray data = facebookFriends.data;
var friends = data.Where<JsonObject>(d => d["name"].ToString().StartsWith("D"));
But in the last line i get the following compile error:
“‘Facebook.JsonArray’ does not contain a definition for ‘Where’ and the best extension method overload ‘System.Linq.ParallelEnumerable.Where(System.Linq.ParallelQuery, System.Func)’ has some invalid arguments”
So, how can i do it?
You can’t use
Where<JsonObject>becauseJsonArrayisIEnumerable<JsonValue>, notIEnumerable<JsonObject>.On the other hand, you don’t have to specify the type using
Where<>extension method:This will make
dvariable inside lambda expression be ofJsonValue.If you want iterate over
JsonObjectelements only you have to addOfTypemethod beforeWhere(but I haven’t really tested if it works):