title: Querying a complex Json with Linq
body: <p>I would like to make a Linq query in a json string.</p>
  
  <p>little info about what i'm trying to do. At work we have a web based schedule system which don't have a support for windows 8 and windows phone 8 app. That is why I decided to make one. Using HttpClient I get an http string which I then convert to xml then Json. <strong>As you can see from the (Link below, the 'TheWholeJsonString.json' file) the property name and JSON object name is not informative and the JSON file is complicated</strong>. That is why I decided to extract some of the values from the JSON string and write a totally new JSON file that include the extracted JSON values in a more informative way. </p>
  
  <p>The [tr] array in the original JSON file have several JSON Objects. Inside the 'VeryShorten.json' file in the linked folder you can see the structure of one of those objects (OBS! there is objcet with different structure). The only thing I hide is the Name and E-Mail address of RL ppl. </p>
  
  <p>I also attached 'ShortenVersion.json' which is only a shorten version of the whole json string, just to make it easy to handle. </p>
  
  <p><a href="http://1drv.ms/OTz1F3" rel="nofollow">Json data sample</a></p>
  
  <pre><code>{
      "@class": "odd",
      "td": [
        {
          "@class": "user",
          "@onmouseover": "userInfo('149');",
          "@onmouseout": "userInfo(0);",
          "@onmousemove": "moveSlotInfo();",
          "#text": " ",
          "a": {
            "@href": "Name3@dreamnet.com",
            "#text": "Name3"
          }
        },
        .
        .
        .
  </code></pre>
  
  <p>In C# if i try the following code (which is not Linq) </p>
  
  <pre><code>var jObject = JObject.Parse(jString); //jString is 'TheWholeJsonString.json' file in the attached link
  
  var jObj = jObject["tbody"]["tr"][8];
  var gh = jObj.Value&lt;JToken&gt;("td").Children().First().Value&lt;JToken&gt;("a").Value&lt;string&gt;("#text");
  </code></pre>
  
  <p>i can get the value of '#text' which is *'Name3'.</p>
  
  <p>However if i try the following code (Linq version):-</p>
  
  <pre><code>var jObject = JObject.Parse(jString);
  var jCollection = jObject["tbody"]["tr"].Children();
  var test = from userToken in jCollection
              where
                  userToken.Value&lt;JToken&gt;("td")
                      .Children()
                      .First()
                      .Value&lt;JToken&gt;("a")
                      .Value&lt;string&gt;("#text")
                      .Contains("Name3")
              select (string)userToken["#text"];
  foreach (var item in test)
  {
     var fgh = item.Type;
  }
  </code></pre>
  
  <p>It will break on the first iteration of foreach loop with the following error msg "Cannot access child value on Newtonsoft.Json.Linq.JValue". I really now what is causing the problem, but i don't know how to solve it. The problem is that not every token inside jCollection have a 'td' object and even if the token have 'td' object it is not Always it have token 'a'. You can see this either in the 'TheWholeJsonString.json' or 'ShortVersion.json' files which i attached in the link. 
  Hope this will explain more info.</p>
  
  <p>So the question is:- Anyone can help to solve this problem?</p>