How to perform linq query in JsonArray from Facebook C# SDK?

c#, facebook-c#-sdk, linq

Solution

You can't use `Where<JsonObject>` because `JsonArray` is `IEnumerable<JsonValue>`, not `IEnumerable<JsonObject>`.

On the other hand, you don't have to specify the type using `Where<>` extension method:

var friends = data.Where(d => d["name"].ToString().StartsWith("D"));

This will make `d` variable inside lambda expression be of `JsonValue`.

If you want iterate over `JsonObject` elements only you have to add `OfType` method before `Where` (but I haven't really tested if it works):

var friends = data.OfType<JsonObject>().Where(d => d["name"].ToString().StartsWith("D"));

Problem

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?

Original source