I have a JSON that might contain an array of string elements and I want to save it to a variable. So far I did:
import SwiftyJSON
(...)
var myUsers = [""]
if(json["arrayOfUsers"].string != nil)
{
myUsers = json["arrayOfUsers"] //this brings an error
}
The error says:
cannot subscript a value of type JSON with an index of type string
How can I pass this array safely to my variable?
json["arrayOfUsers"]is a string and then you try to assign this object to an array of strings - it won't work. Please tell us what isjson["arrayOfUsers"], is it a string or an array?["5523533","5gdsgdse","5gdsgsdb9","5432523d"]myUsers = json["arrayOfUsers"].arraybut then I'm getting an errorcannot assign value of type [JSON] to type [String]myUsersto be[""]AKA[String]