1

Using JSON.Net (http://www.newtonsoft.com/json/help/html/LINQtoJSON.htm) and the following code:

@using Newtonsoft.Json;
@using Newtonsoft.Json.Linq;


@{

    var url = "https://graph.facebook.com/v2.2/me&fields=id%2Cname%2Cposts.limit(3)&format=json&method=get&pretty=0&suppress_http_code=1";
    var syncClient = new WebClient();
    var content = syncClient.DownloadString(url);

    JObject facebook = JObject.Parse(content);

    //To-Do: Get all messages as list<string> using LINQ for JSON
    // Ex:  IList<string> allDrives = o["Drives"].Select(t => (string)t).ToList();




}

How would I get a List<> of all messages given the following JSON format (http://www.codeshare.io/EvIdN).

Thanks in advance!

1
  • +1 that this code is working and cool, i've being looking for something like that in w while, thank you so much, the answer is also working Commented Oct 10, 2017 at 9:34

1 Answer 1

3

Selecting all messages as strings (no error checking):

var arr = ((JArray) obj["posts"]["data"]).Select(e => (string) ((JValue) e["message"]).Value).ToList();
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly, thank you! I will be sure to build in the error checking.
great way to querry the data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.