title: Converting JSON from AlamoFire/SwiftyJSON to Dictionary in Swift/Xcode
body: <p>My head is going to explode :)  - I've been trying to get a JSON String from my server to a Dictionary Value, and I can't get it to work.</p>
  
  <p>I'm trying to get (from my Server - this is dynamic and I want my app to be able to pull new data from the server when needed):</p>
  
  <pre><code>{"1":"Location 1","2":"Location 2","3":"Location 3"}
  </code></pre>
  
  <p>To this Dictionary in Xcode using Swift:</p>
  
  <pre><code>  var labels = [
  
          1 : "Location 1",
          2 : "Location 2",
          3 : "Location 3"
  
      ]
  </code></pre>
  
  <p>This has got to be pretty straight forward, but for the life of me I can't figure it out...</p>
  
  <p>Here's my Swift - I can get it to pull the information from the server, but I can't get it into a dictionary like I need</p>
  
  <pre><code>var postEndpoint: String = "http://www.myserver.net/app/campus.php"
  
      Alamofire.request(.GET, postEndpoint)
          .responseJSON { (request, response, data, error) in
              if let anError = error
              {
                  println("error")
                  println(error)
              }
              else if let data: AnyObject = data 
              {
                   let post = JSON(data)
                   println(post)
              }
      }
  </code></pre>
  
  <p>which results in:</p>
  
  <pre><code>{
    "1" : "Location 1",
    "2" : "Location 2",
    "3" : "Location 3"
  }
  </code></pre>
  
  <p>The End Result that I'm using this for is an iBeacon implementation with the following code:</p>
  
  <pre><code> let knownBeacons = beacons.filter{ $0.proximity != CLProximity.Unknown }
      if (knownBeacons.count &gt; 0) {
          let closestBeacon = knownBeacons[0] as CLBeacon
  
          let locationID = post[closestBeacon.minor.integerValue]
  
          self.locationLabel.text = locationID
          self.view.backgroundColor = self.colors[closestBeacon.minor.integerValue]
      }
  </code></pre>
  
  <p>The error I'm getting is at self.locationLabel.text = locationID  'JSON' is not convertible to 'String', I do not get this error when I use the static var labels dictionary.  Am I trying to get the data from the server incorrectly?  What am I doing wrong???  I think the var labels having an undeclared Type allows Swift to figure out what it needs to, how do I do the same from the JSON part?</p>