I need to get string from the JSON Array which is a response from the external server. This is my code:
if let dictionary = NSJSONSerialization.JSONObjectWithData(data,options: NSJSONReadingOptions.MutableContainers,error: &parsingError) as NSDictionary?{
var info : NSArray = dictionary.valueForKey("data") as NSArray
var names: String? = info[0].valueForKey("firstname") as? String
println("name ++\(names)")
}
It's compiling but when I execute, not running I got as
thread 8:exc_bad_access (code=2 ..
This is Dictonary coming from server side
{
data = {
Id = 55;
firstName = fgg;
gender = 1;
};
success = 1; }
I followed thread without success : Getting Values from JSON Array in Swift
Can anyone help me to get this string out? I cannot find out the error I have done here. Any help would be appreciated.
var info : NSDictionary = dictionary.valueForKey("data") as NSDictionary var names: String? = info["firstName"] as? String println("name ++\(names)")