title: Swift 3 - How to get JSON Objects with Alamofire and SwiftyJSON
body: <p>I want to use Alamofire and SwiftyJSON for my REST api.I have accessed the root json but i can't access the objects of json. What is the best way to parse it correctly combining these two libraries?</p>
  
  <p>My JSON:-</p>
  
  <pre><code>[
  {
      "ID": 2,
      "Nm": "ABC",
      "Descr": null,
      "BeenCnt": "9",
      "FavCnt": "9",
      "ImgPath": "pathtoimage",
      "TypeID": 4,
      "Type": null,
      "DayCnt": 5,
      "NightCnt": 4,
      "ValidDate": null,
      "UsrCommentCnt": null,
      "TourDates": null,
      "CityList": [
          {
              "KeyID": null,
              "ID": 1,
              "Data": "abc"
          },
          {
              "KeyID": null,
              "ID": 12,
              "Data": "abc"
          }
      ],
      "Seller": {
          "ID": 1,
          "Nm": "abc",
          "CityNm": null,
          "StateNm": null,
          "CommentCnt": null,
          "BeenCnt": null,
          "Add": null,
          "PackList": []
      },
      "Chrg": {
          "ID": 0,
          "PaxDetail": "Per Person",
          "PkgMode": null,
          "Amt": 15000,
          "AmtCurrID": 2,
          "AmtCurr": null,
          "ChargeSeq": 0
      },
      "ItineraryList": []
  }
  </code></pre>
  
  <p>I want 'Chrg' to populate in my <code>UICollectionView</code>.</p>
  
  <p>What i am trying in coding:-</p>
  
  <pre><code>Alamofire.request(url).responseJSON { (responseData) -&gt; Void in
  
  
          if((responseData.result.value) != nil) {
              let swiftyJSONVar = JSON(responseData.result.value!)
  
              if let resData = swiftyJSONVar[].arrayObject
              {
                  self.arrRes = resData as! [[String:AnyObject]]
                  print(self.arrRes)
              }
  
              if self.arrRes.count &gt; 0 {
                  self.collection.reloadData()
              }
  
          }
      }
  </code></pre>
  
  <p>My <code>UICollectionViewCell</code> :-</p>
  
  <pre><code>  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! PackagesCell
      var dict = arrRes[(indexPath as NSIndexPath).row]
      var charge = dict["Chrg"] as! Dictionary&lt;String,String&gt;
      cell.amtLbl.text = charge["Amt"] as? String
      cell.NmLbl.text = dict["Nm"] as? String
      cell.nightsLbl.text = String(Int((dict["NightCnt"] as! Int64)))
      cell.dayLbl.text = String(Int(dict["DayCnt"] as! Int64))
  
      cell.perPersonLbl.text = dict["PaxDetail"] as? String
      cell.validTillLbl.text = dict["ValidDate"] as? String
      cell.iternaryListLbl.text = dict["CityList"]?["Data"] as? String
      cell.cmtLbl.text = dict["BeenCnt"] as? String
      cell.beenCmtLbl.text = dict["FavCnt"] as? String
      self.id = String(dict["ID"] as! Int64)
      let ImgPath = dict["ImgPath"] as? String
      let fulURL = "\(self.site + ImgPath!)"
      let newURL = fulURL.replacingOccurrences(of: "\\", with: "/")
      let newwURL = newURL.replacingOccurrences(of: "png", with: "jpg")
      cell.img.sd_setImage(with: URL(string:newwURL),  placeholderImage: UIImage(named: "placeholder.png"))
      return cell
  }
  </code></pre>