简体   繁体   中英

Cannot call value of non-function type 'NSDictionary'

In the following part of my code i get the issue

Cannot call value of non-function type 'NSDictionary'

do {
    var json = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers) as? NSDictionary
      if let parseJSON = json {
        var resultValue: String = parseJSON ("status") as String!
        print ("result:\(resultValue)")         
        if resultValue == "success" {
          // Login is successful
          NSUserDefaults.standardUserDefaults().setBool(true, forKey: ("isUserLoggedIn"))
          NSUserDefaults.standardUserDefaults().synchronize()
          self.dismissViewControllerAnimated(true, completion: nil)
        }
      }     
    } catch let error as NSError{
  print("error=\(error)")            
}

I already tried to place the if statement outside the do catch statement, but then i get the issue "Use of unresolved identifier 'json'

This part of your code:

String = parseJSON ("status")

is trying to call an array or (in this case) dictionary as a function. The syntax you're looking for uses [] instead of () :

String = parseJSON["status"]

You also shouldn't be using brackets in your user default code:

forKey: "isUserLoggedIn")

if you're not careful with brackets you start to define tuples and run into other issues...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM