title: Deserialize Google Directions JSON
body: <p>First time working with JSON and related, I'm trying to get distance/duration of all possible routes from this request: <a href="https://maps.googleapis.com/maps/api/directions/json?origin=41.2091585,-8.5763016&amp;destination=41.258913,-8.636942&amp;mode=driving&amp;alternatives=true&amp;avoid=tolls&amp;language=pt-PT&amp;key=AIzaSyDuhdvLAny3MpraXKX-bahkXZJolm7KLbE" rel="nofollow">https://maps.googleapis.com/maps/api/directions/json?origin=41.2091585,-8.5763016&amp;destination=41.258913,-8.636942&amp;mode=driving&amp;alternatives=true&amp;avoid=tolls&amp;language=pt-PT&amp;key=AIzaSyDuhdvLAny3MpraXKX-bahkXZJolm7KLbE</a>  </p>
  
  <p>I got the following classes using "Paste JSON as Classes" and create one Class for each of the following ones:    </p>
  
  <pre><code>public class Rootobject
      {
          public Geocoded_Waypoints[] geocoded_waypoints { get; set; }
          public Route[] routes { get; set; }
          public string status { get; set; }
      }
  
  public class Route
      {
          public Bounds bounds { get; set; }
          public string copyrights { get; set; }
          public Leg[] legs { get; set; }
          public Overview_Polyline overview_polyline { get; set; }
          public string summary { get; set; }
          public object[] warnings { get; set; }
          public object[] waypoint_order { get; set; }
      }
  
  public class Leg
      {
          public Distance distance { get; set; }
          public Duration duration { get; set; }
          public string end_address { get; set; }
          public End_Location end_location { get; set; }
          public string start_address { get; set; }
          public Start_Location start_location { get; set; }
          public Step[] steps { get; set; }
          public object[] traffic_speed_entry { get; set; }
          public Via_Waypoint[] via_waypoint { get; set; }
      }
  
  public class Distance
      {
          public string text { get; set; }
          public int value { get; set; }
      }
  
  public class Duration
  {
      public string text { get; set; }
      public int value { get; set; }
  }
  </code></pre>
  
  <p>For the query mentioned above I have 3 different routes (aka "legs") and I want to get the distance/duration of each one.<br>
  I came up with the following but it's not working.  </p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query);
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  using (var streamReader = new StreamReader(response.GetResponseStream()))
  {
      var result = streamReader.ReadToEnd();
  
      if (!string.IsNullOrEmpty(result))
      {
          Distance t = JsonConvert.DeserializeObject&lt;Distance&gt;(result);
          string distance1_Value = t.value;
          string distance1_Text = t.text;
  
          Duration d = JsonConvert.DeserializeObject&lt;Duration&gt;(result);
          string duration1_Value = d.value;
          string duration1_Value = d.text;
      }
  }
  </code></pre>
  
  <p>Any help?<br>
  PS: If anyone can show me how to iterate throw each "legs" that would be great.  </p>
  
  <p>EDIT: Forgot to mention I'm using Newtonsoft.</p>