0

I'm working with Alamofire and SwiftyJSON. I'm trying to make a request with the following structure

{
    "email":"[email protected]",
    "password":"pppppp",
    "categories": [
        {"id":"2"},
        {"id":"1"},
        {"id":"6"},
        {"id":"5"}       
        ]
}

I'm using :

let parameters = [     
                       "email" : userEmail,
                  "categories" : userPassword,
                  "categorias" : selectedCategoriesArray]

//where selectedCategoriesArray is a [[String]]()

I fill my selectedCategoriesArray in a loop with this line modifying the array:

selectedCategoriesArray.append(["id", "2"]) //where 2 can be any other number

Alamofire.request( .PUT, url, parameters)

It seems it's working fine but it isn't, I don't know if my String array is taking the right format to be sent to the WS or do I need to encode it in a special way?

Has anyone worked with something like this, A little help would be appreciate. Thanks!

2 Answers 2

1

I think your array should have a type of [[String: String]] in this case.

let userEmail = "[email protected]"
let userPassword = "123456"

var selectedCategoriesArray: [[String: String]] = []
for i in 0...5 {
  selectedCategoriesArray.append(["id": String(i)])
}

let parameters = [
  "email" :      userEmail,
  "password" :   userPassword,
  "categories" : selectedCategoriesArray
]
Sign up to request clarification or add additional context in comments.

Comments

0

Check with below

let savedData = ["id": 1, "id": 2]

let jsonObject: [String: AnyObject] = [
    "email": “[email protected]”,
    "password": 123456,
    "categories": savedData
]

let valid = NSJSONSerialization.isValidJSONObject(jsonObject) // true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.