title: How to parse response from google maps API with JSON?
body: <p>I want to calculate the distance between points in C# with the google maps distance matrix API.</p>
  
  <p>I use the following code to make the request : </p>
  
  <pre><code>private void MapsAPICall()
      {
          //Pass request to google api with orgin and destination details
          HttpWebRequest request =
              (HttpWebRequest)WebRequest.Create("http://maps.googleapis.com/maps/api/distancematrix/json?origins="
              + "51.123959,3.326682" + "&amp;destinations=" + "51.158089,4.145267" 
              + "&amp;mode=Car&amp;language=us-en&amp;sensor=false");
  
          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);
              }
          }
      }
  </code></pre>
  
  <p>And then I want to parse the json answer into the Distance class:</p>
  
  <pre><code>public struct Distance
  {
     // Here I want to parse the distance and duration
  }
  </code></pre>
  
  <p>Here is an example of the json response I receive : 
  <a href="http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC&amp;destinations=San+Francisco&amp;mode=bicycling&amp;language=fr-FR&amp;sensor=false" rel="nofollow">http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC&amp;destinations=San+Francisco&amp;mode=bicycling&amp;language=fr-FR&amp;sensor=false</a></p>
  
  <p>How do I parse the distance and duration into the Distance class?<br>
  This is the first time I use Json so I'm not experienced with it. </p>
  
  <p>Ps: I have the json.net library installed.</p>