0
{
    "firstName": "AA",
    "lastName": "BB,
    "shortName": "CC",
    "nric": "12/AAA(N)123456",
    "gender": "F",
    "dob": "1.1.2000",
    "password": "admin123",
    "photo": {
        "image": "hello",
        "thumb": "world"
    }
}

Is there anyway how to add photo array in main array? I've done as follow

let photoArray = [
    "image": imageBase64,
    "thumb": imageBase64
]

let param = [
    "firstName": txtFirstName.text as! AnyObject,
    "lastName": txtLastName.text as! AnyObject,
    "shortName": txtShortName.text as! AnyObject,
    "nric":"",
    "gender": genderCode,
    "dob":txtDOB.text as! AnyObject,
    "photo": photoArray
]

but output is awful. Please let me how to do it.

4
  • Array or Dictionary? Commented Jul 11, 2016 at 5:26
  • you are making a dictionary not an array Commented Jul 11, 2016 at 5:26
  • @BhumitMehta dictionary instead Commented Jul 11, 2016 at 5:27
  • please let me know how to implement it? Commented Jul 11, 2016 at 5:33

3 Answers 3

2

Instead of making the param let make it var and do the following. You do need to specify the dictionary type as below

let photoArray : [String : AnyObject] = [
            "pic" : "myPhoto"
        ]
var param : [String : AnyObject] = [
            "name" : "UserName"
        ]

param["photo"] = photoArray
Sign up to request clarification or add additional context in comments.

Comments

1
    let photoArray = [[
        "image": "a",
        "thumb": "b"],[
            "image": "a",
            "thumb": "b"]
    ]
let param = [
"firstName": txtFirstName.text as! AnyObject,
"lastName": txtLastName.text as! AnyObject,
"shortName": txtShortName.text as! AnyObject,
"nric":"",
"gender": genderCode,
"dob":txtDOB.text as! AnyObject,
"photo": photoArray

]

Hope you want like this.

Comments

1
let photoArray:[String:UIImage] = [
    "image": UIImage.init(named: "a.png")!,
    "thumb": UIImage.init(named: "b.png")!
]

let param:[String:AnyObject] = [
    "firstName": "AA",
    "lastName": "BB",
    "shortName": "CC",
    "nric": "",
    "gender": 0,
    "dob": "DD",
    "photo": photoArray
]

You can do it like this

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.