0

Alamofire - SWIFT JSON ARRAY

I want to Pass JSON ARRAY like this -

[
   {
      "OrgId": 1001,
      "ClassworkId": 999800580,
   }, {
      "OrgId": 1001,
      "ClassworkId": 0,
   }
]

I am Using this Method - I want to solve parameter - [String : AnyObject] -> Array

func delateClasswork (parameters: [String: AnyObject],completion: (success : Bool) -> Void) {
    request(.POST, "strURL", parameters: parameters, encoding:.JSON).responseJSON {
    response in switch response.result {
       case .Success(let JSON):
       if((JSON.valueForKey("StatusId")) as! NSNumber == 1){
           completion(success: true)
           break
       }else{
           completion(success: true)
           break
       }
       case .Failure(let error):
           completion(success : false)
           break
       }
   }
}
Nirav D
  • 71,513
  • 12
  • 161
  • 183

1 Answers1

1

Assign the whole data to one parameter data, this will maintain the Type to [String:AnyObject].

let parameters:[String:AnyObject] = [
    "data" : [
        [
            "OrgId": 1001,
            "ClassworkId": 999800580,
        ],
        [
            "OrgId": 1001,
            "ClassworkId": 0,
        ]
    ]
]

At the server end you have to parse the data using data key.

Bista
  • 7,869
  • 3
  • 27
  • 55