lundi 14 novembre 2016

The correct JSON comparison with Strings (SWIFT 3)

    request( url!, method: .get, parameters: nil)
        .responseJSON { response in

            print(response.result)   // result of response serialization

            if let newJSON = response.result.value {
                let json = JSON(newJSON)
                for (key,subJson):(String, JSON) in json {

                    let age = subJson["age"]
                    let name = subJson["name"]
                    let status = subJson["status"]

  //the code below looks kind of confusing if it gets longer

                    if age == "22"{
                        if status == "highschool "{
                            if name == "Leo"{
                              //do something with the result 

Is there a better way of checking if the result from JSON is same as the Strings?

Aucun commentaire:

Enregistrer un commentaire