title: parse JSON array with json.NET and C#
body: <p>I have some data in the following JSON format that I need to parse:</p>
  
  <pre><code>{
  "status":0,
  "timestamp":"8:20pm",
  "routes":[
      {
          "directions":[
              "E Towne",
              "ETP"
          ],
          "routeID":"30"
      },
      {
          "directions":[
              "Johnson",
              "Observatory"
          ],
          "routeID":"81"
      }
  ]
  }
  </code></pre>
  
  <p>Using json.net, I have got want to get the following output:</p>
  
  <blockquote>
    <p>30 E Towne – ETP</p>
    
    <p>81 Johnson – Observatory</p>
  </blockquote>
  
  <p>Using the code below, I get the following incorrect output:</p>
  
  <blockquote>
    <p>30 E Towne – ETP</p>
    
    <p>81 E Towne – ETP</p>
  </blockquote>
  
  <p>How do I write out the directions array items to the corresponding routeID item?  My code:</p>
  
  <pre><code>public class Route
          {
              public string routeID { get; set; }
              public string directions { get; set; }  
          }
  
  private void routeClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
          {
              string jsonResults_routes = e.Result;
              JObject routeData = JObject.Parse(jsonResults_routes);
  
              JArray routeIdArray = (JArray)routeData["routes"];
              JArray routeDirections = (JArray)routeData["routes"][0]["directions"];
  
              List&lt;Route&gt; l = new List&lt;Route&gt;();
  
              for (int i = 0; i &lt; routeIdArray.Count; i++)
              {
                  Route BusRoutes = new Route();
  
                  JObject routeIDarrayObject = (JObject)routeIdArray[i];
                  BusRoutes.routeID = (string)routeIDarrayObject["routeID"];
  
                  string sep = " - ";
                  string bothDirections = String.Join(sep, routeDirections);
  
                  List&lt;string&gt; sc = new List&lt;string&gt;();
                  string[] direction = new string[]{bothDirections};
                  sc.AddRange(direction);
  
                  foreach (string direx in sc)
                  {
                      BusRoutes.directions = direx; 
                  }
  
                  l.Add(BusRoutes);
  
              }
              var newList = l.OrderBy(x =&gt; x.routeID).ToList();
              lbRoutesData.ItemsSource = newList;
          }
  </code></pre>