Получение ответа из php в приложение


#1


можете посмотреть все ли правильно работает! код самого приложения ниже


#2
import UIKit

class ViewController: UIViewController, UITextFieldDelegate {
    
 let URL_SAVE_TEAM =  "http://172.30.31.250/iosmaster/selectteam.php"
    @IBOutlet weak var textFieldLogin: UITextField!
    
    @IBOutlet weak var textFieldPassword: UITextField!
    
    @IBOutlet weak var textFieldIdentificator: UITextField!
    
    
    @IBAction func Cancel(_ sender: UIButton) {
        textFieldLogin.text = ""
        textFieldPassword.text = ""
        textFieldIdentificator.text = ""
    }
    
    @IBAction func Keyboard(_ sender: Any) {
        textFieldLogin.resignFirstResponder()
        textFieldPassword.resignFirstResponder()
        textFieldIdentificator.resignFirstResponder()
    }
    
    @IBAction func buttonSave(_ sender: UIButton) {
      
        let requestURL = URL(string: URL_SAVE_TEAM)
        
        //создание NSMutableURLRequest
        let request = NSMutableURLRequest(url:requestURL!)
        
        //установка метода для публикации
        request.httpMethod = "POST"
        
        //получение значений из текстовых полей
        let teamLOGIN=textFieldLogin.text
        let  memberPASS=textFieldPassword.text
        //let teamidAcc = textFieldIdentificator.text
        //создание параметра post путем конкатенации ключей и значений из текстового поля
       
         //let postParameters = "LOGIN="+teamLOGIN+"&PASS="+memberPASS;//+"&idAcc="+teamidAcc!;
        let postParameters: Dictionary<String, Any> = [ "LOGIN": teamLOGIN as Any, "PASS": memberPASS as Any]
        
        if (!JSONSerialization.isValidJSONObject(postParameters)) {
            return
        }
        
        request.httpBody = try! JSONSerialization.data(withJSONObject: postParameters, options: JSONSerialization.WritingOptions.prettyPrinted)
        //adding the parameters to request body
        //request.httpBody = postParameters.data(using: String.Encoding.utf8)
        
        
        //создание задачи для отправки запроса на отправку
        let task = URLSession.shared.dataTask(with: request as URLRequest){
            data, response, error in
            
            if error != nil{
                print("error is \(String(describing: error))")
                return;
            }
            
            //анализ ответа
            //do {
                //преобразование ответа в NSDictonary
               // let myJSON =  try JSONSerialization.jsonObject(with:data!, options: .mutableContainers) as? NSDictionary
                let myJSON =  (try? JSONSerialization.jsonObject(with:data!, options: [])) as? Dictionary<String, Any>
                //разбор json
                if let parseJSON = myJSON {
                    
                    //создание строки
                    var msg : String!
                    
                    //получение ответа json
                    msg = parseJSON["message"] as! String?
                    
                    //печать ответа
                    print(msg)
                    
                }
            //} catch {
                print(error)
            //}
            
        }
        //выполнение задачи
        task.resume()
        
    }
    
}

#3

В php точно ошибка в логике:
$output, выводите за приделами while
Не будут лишними и заголовки, что на выходе json