テキストフィールドに書き込まれたjsonにデータを保存できません。保存ボタンをクリックすると、更新されたデータをjsonに保存する必要があります。 は、ここで私はボタンアクションを保存するに書かれているコードです:ポストデータコードのポストを使用してjsonにデータを保存できません
if let id = UserDefaults.standard.string(forKey: "NgoId"){
var request = URLRequest(url: URL(string: "http://www.shreetechnosolution.com/funded/ngo_profile.php?ngoid=\(id)")!)
request.httpMethod = "POST"
let postString = "Nameofngo=\(textngoname.text!)&NameofChiefFunctionary=\(textcheiffunction.text!)&NameofChairman=\(textchairman.text!)&NameofSeceratary=\(textsecratary.text!)&NameofTreasurer=\(texttreasurer.text!)&ParentOrganization=\(textparentorg.text!)&AboutNGO=\(Textngo.text)&photoofNGO=\(imageviewngo.image)&ngoid=\(id)&value=NGO"
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else { // check for fundamental networking error
print("error=\(error ?? "" as! Error)")
return
}
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(String(describing: response))")
}
let json = try! JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary
let msg = json.value(forKey: "message") as! NSString!
let alert : UIAlertView = UIAlertView(title: "Alert box!", message: "\(msg!).",delegate: nil, cancelButtonTitle: "OK")
alert.show()
}
task.resume()
}
httpStatusコードの記録を表示できますか?そして、テストする1サンプルのNgoIdキーをつけてください。 – Warewolf