Reputation: 21
i want to post nested json objects in API using Alamofire my objects structere is like this
["example" :
{
"fname":"john",
"lnamed":"Doe"
},{
"fname":"john",
"lname":"Doe"
},
.
.
.
]
my problem is when i'm making array it becomes like ["example":[["fname":"john","lname":"Doe"],["fname":"john","lname":"Doe"]]] so their is one square bracket extra because of the array. below is 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]
Upvotes: 1
Views: 716
Reputation: 21
after while i discovered my problem was with the Alamofire request i forgot to add the encoding parameter and the solution is
Alamofire.request("https://httpbin.org/post", parameters: parameters, encoding: URLEncoding.httpBody)
Upvotes: 1