Istorn
Istorn

Reputation: 596

Convert "Any" array to String in swift 3

Having this code:

let object = json as? [Any] {
    if let questionari=object["questionnarie"] as? [Dictionary<String, AnyObject>]{
}

Compiler (of course) says to me that I can't use a String's index while it's [Any]: I can't find the proper why to cast it as String.

Upvotes: 1

Views: 5712

Answers (3)

Kuldip
Kuldip

Reputation: 1

you can make componentsJoined string with "," from any array.

like one line code see bellow example:

let yourStringVar = NSArray(array:ANY_ARRAY_NAME).componentsJoined(by: ",")

Upvotes: 0

Abhishek Jain
Abhishek Jain

Reputation: 4739

Try this code-

if let object = json as? [String:Any] {
    if let questionari=object["questionnarie"] as? [Dictionary<String, AnyObject>]{
}

Upvotes: 1

Martin Muldoon
Martin Muldoon

Reputation: 3428

You should be casting your json object as so:

if let object = json as? [String:Any] {
...

Upvotes: 3

Related Questions