title: Parsing json data from google maps api in swift
body: <p>I was in the process of parsing JSON data from the google maps API to get my current location city using longitude &amp; latitude.</p>
  
  <p>But now im stuck with my code here and i cannot access the data in the results. For instance i want to get the data in the "administrative_area_level_2" for the key "long name". How can i access it?</p>
  
  <pre><code>dispatch_async(dispatch_get_main_queue(), {
  
              if let urlContent = data{
                  do{
                      let jsonResult = try NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
                      if let results = jsonResult["results"] as? [[String : AnyObject]] {
  
                          for result in results{
  
                              if let addressComponents = result["address_components"] as? [[String : AnyObject]] {
  
                                  print(addressComponents)
                              }
                          }
                      }
                    //  print(jsonResult)
  
                  } catch{
  
                  }
  
              }
  
          })
  </code></pre>
  
  <p>Here are the addressComponents JSON results in console:</p>
  
  <pre><code>    [["types": (
      route
  ), "short_name": Abou Al MAGD Al Askalani, "long_name": Abou Al MAGD Al Askalani], ["types": (
      "administrative_area_level_3",
      political
  ), "short_name": Al Golf, "long_name": Al Golf], ["types": (
      "administrative_area_level_2",
      political
  ), "short_name": Nasr City, "long_name": Nasr City], ["types": (
      "administrative_area_level_1",
      political
  ), "short_name": Cairo Governorate, "long_name": Cairo Governorate], ["types": (
      country,
      political
  ), "short_name": EG, "long_name": Egypt]]
  </code></pre>
  
  <p>Here are the results jsonResult results in console:</p>
  
  <pre><code>results =     (
              {
          "address_components" =             (
                              {
                  "long_name" = "Abou Al MAGD Al Askalani";
                  "short_name" = "Abou Al MAGD Al Askalani";
                  types =                     (
                      route
                  );
              },
                              {
                  "long_name" = "Al Golf";
                  "short_name" = "Al Golf";
                  types =                     (
                      "administrative_area_level_3",
                      political
                  );
              },
                              {
                  "long_name" = "Nasr City";
                  "short_name" = "Nasr City";
                  types =                     (
                      "administrative_area_level_2",
                      political
                  );
              },
                              {
                  "long_name" = "Cairo Governorate";
                  "short_name" = "Cairo Governorate";
                  types =                     (
                      "administrative_area_level_1",
                      political
                  );
              },
                              {
                  "long_name" = Egypt;
                  "short_name" = EG;
                  types =                     (
                      country,
                      political
                  );
              }
          );
  </code></pre>