title: Parse json from google maps reverse geocode?
body: <p>How can I parse through the response from a reverse geocode using Google Maps JavaScript API v3.</p>
  
  <pre><code>geocoder.geocode({'latLng': latlng}, function(results, status) {
                  if (status == google.maps.GeocoderStatus.OK) {
                      if (results[0]) {
                          infowindow.setContent(results[0].formatted_address);
                          infowindow.open(map, marker);
                      }
                  } 
  </code></pre>
  
  <p>This displays the formatted address fine in the popup, but I'm trying to take other bits out of the response, ideally the street name or route (if no street name found). But when using  <code>obj = JSON.parse(json);</code> I keep getting this error in the console. </p>
  
  <blockquote>
    <p>SyntaxError: JSON.parse: unexpected character</p>
  </blockquote>
  
  <p>if it were PHP I would do a bunch of <code>for each</code> loops. Is it possible to do something similar in JavaScript ? </p>
  
  <p>heres a sample</p>
  
  <pre><code>{
     "results" : [
    {
       "address_components" : [
          {
             "long_name" : "131",
             "short_name" : "131",
             "types" : [ "street_number" ]
          },
          {
             "long_name" : "Stubbington Avenue",
             "short_name" : "Stubbington Ave",
             "types" : [ "route" ]
          },
          {
             "long_name" : "Portsmouth",
             "short_name" : "Portsmouth",
             "types" : [ "locality", "political" ]
          },
          {
             "long_name" : "Portsmouth",
             "short_name" : "Portsmouth",
             "types" : [ "administrative_area_level_3", "political" ]
          },
          {
             "long_name" : "Portsmouth",
             "short_name" : "Portsmouth",
             "types" : [ "administrative_area_level_2", "political" ]
          },
          {
             "long_name" : "England",
             "short_name" : "England",
             "types" : [ "administrative_area_level_1", "political" ]
          },
          {
             "long_name" : "United Kingdom",
             "short_name" : "GB",
             "types" : [ "country", "political" ]
          },
          {
             "long_name" : "PO2",
             "short_name" : "PO2",
             "types" : [ "postal_code_prefix", "postal_code" ]
          },
          {
             "long_name" : "Portsmouth",
             "short_name" : "Portsmouth",
             "types" : [ "postal_town" ]
          }
       ],
       "formatted_address" : "131 Stubbington Avenue, Portsmouth PO2, UK",
       "geometry" : {
          "location" : {
             "lat" : 50.8170795,
             "lng" : -1.0709701
          },
          "location_type" : "ROOFTOP",
          "viewport" : {
             "northeast" : {
                "lat" : 50.81842848029149,
                "lng" : -1.069621119708498
             },
             "southwest" : {
                "lat" : 50.8157305197085,
                "lng" : -1.072319080291502
             }
          }
       },
       "types" : [ "street_address" ]
    }
     ],
  "status" : "OK"
  }
  </code></pre>
  
  <p>also heres a <a href="http://seriousbrew.co.uk/dev/examples/tools.html" rel="nofollow">link to my dev page</a> with my current code in full</p>
  
  <p>In summary, how do I get "Stubbington Avenue" from that mess up there ?</p>