Json post nested objects in swift using alamofire

I want to post nested json objects to API using Alamofire, my structere objects are like this

["example" :
 {
 "fname":"john",
 "lnamed":"Doe"
 },{
 "fname":"john",
 "lname":"Doe"
 },
.
.
.
]

      

My problem is that when I make an array it becomes like ["example": [ ["fname": "john", "lname": "Doe"], ["fname": "John", "LNAME" : "Doe"] ] ] so their one square bracket is extra because of the array. below are my codes.

var exampleObj = [String:AnyObject]()

var examplesArray  = [exampleObj]

    for example in examples
    {

        exampleObj = ["fname":example[fname] as AnyObject, "lname":example["lname"] as AnyObject]

        examplesArray.append(exampleObj)
    }



        let parameters = ["example": examplesArray] 

      

+1


source to share


1 answer


after i found my problem was with Alamofire request i forgot to add encoding parameter and solution



Alamofire.request("https://httpbin.org/post", parameters: parameters, encoding: URLEncoding.httpBody)

      

+1


source







All Articles