Note that there are some explanatory texts on larger screens.

plurals
  1. POIterate through json object in c#
    text
    copied!<p>I' Want to create a loop to check a condition on my Json object. I'm looking for a way to iterate through my json object:</p> <p>Json:</p> <pre><code>{"tasks":[ { "id":-1, "name":"Gantt editor", "code":"", "level":0, "status":"STATUS_ACTIVE", "start":1372608000000, "duration":21, "end":1375113599999, "startIsMilestone":true, "endIsMilestone":false, "collapsed":false, "assigs":[] }, { "id":"tmp_fk1372575559620", "name":"release", "code":"", "level":1, "status":"STATUS_ACTIVE", "start":1372608000000, "duration":1, "end":1372694399999, "startIsMilestone":false, "endIsMilestone":false, "collapsed":false, "assigs":[] } ], // number of tasks may vary "selectedRow":8, "deletedTaskIds":[], "resources": [ { "id":"tmp_1", "name":"Resource 1" } ], "roles":[ { "id":"tmp_1", "name":"Project Manager" } ], "canWrite":true, "canWriteOnParent":true } </code></pre> <p>I know how to map it so let's assume i mapped Task and RootObject as follow:</p> <pre><code>public class Task { public object id { get; set; } public string name { get; set; } public string code { get; set; } public int level { get; set; } public string status { get; set; } public object start { get; set; } public int duration { get; set; } public object end { get; set; } public bool startIsMilestone { get; set; } public bool endIsMilestone { get; set; } public bool collapsed { get; set; } public List&lt;object&gt; assigs { get; set; } } public class RootObject { public List&lt;Task&gt; tasks { get; set; } public int selectedRow { get; set; } public List&lt;object&gt; deletedTaskIds { get; set; } public List&lt;Resource&gt; resources { get; set; } public List&lt;Role&gt; roles { get; set; } public bool canWrite { get; set; } public bool canWriteOnParent { get; set; } } // And etc ..... </code></pre> <p>I know how to check the tasks manually for example for first one</p> <pre><code>Rootobject project = JsonConvert.DeserializeObject&lt;Rootobject&gt;(jsonString); Task task = project.tasks.FirstOrDefault(t =&gt; t.id == "-1"); decimal start = Convert.ToDecimal(task.start); decimal end = Convert.ToDecimal(task.end); decimal prog = Convert.ToDecimal(task.progress); </code></pre> <p>and then use task to check all it's attributes </p> <p>How can I check all tasks ? </p> <p>Thanks In Advance ! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload