私はSwiftとiOSの開発には新人ですが、MySQLデータベースに保存されているデータをダウンロードして解析しようとしています。「Domain = NSCocoaErrorDomain Code = 3840」というエラーが表示されるのはなぜですか? UserInfo = {NSDebugDescription =値なし} '?
私はエラーを取得しておく:
Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}
私は以下の私のコードを掲載しているが、私は問題はparseJSON機能であると思いますが、代わりに、私は印刷するときなど、データの実際のダウンロードではありません'data'は '<>'を返します。ここで
は私のコードです:あなたのコード内
//properties
weak var delegate: HomeModelProtocal!
var data : NSMutableData = NSMutableData()
let urlPath: String = "http://localhost/service.php" //this will be changed to the path where service.php lives
// Function to download the incoming JSON data
func downloadItems(){
let url: URL = URL(string: urlPath)!
var session: URLSession!
let configuration = URLSessionConfiguration.default
session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
let task = session.dataTask(with: url)
task.resume()
}
func urlSession(_ session: URLSession, task: URLSessionDataTask, didCompleteWithError error: Error?) {
self.data.append(data as Data)
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if error != nil{
print("Failed to download data")
}else{
print("Data downloaded")
print(data)
self.parseJSON()
}
}
func parseJSON(){
var jsonResult: NSMutableArray = NSMutableArray()
do{
jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options: []) as! NSMutableArray
} catch let error as NSError {
print("**** sake its happened again \(error)")
}
var jsonElement: NSDictionary = NSDictionary()
let locations: NSMutableArray = NSMutableArray()
for i in 0 ..< jsonResult.count{
jsonElement = jsonResult[i] as! NSDictionary
let location = LocationModel()
//the following insures none of the JsonElement values are nil through optional binding
if let exerciseName = jsonElement["stationName"] as? String,
let bodyPart = jsonElement["buildYear"] as? String
{
print(exerciseName, bodyPart)
location.exerciseName = exerciseName
location.bodyPart = bodyPart
}
locations.add(location)
}
DispatchQueue.main.async(execute: {() -> Void in
self.delegate.itemsDownloaded(items:locations)
})
}
はおそらく、応答が空である。このようなすべてのものは固定して
、あなたはこのような何かを得ることができますか?あなたの 'print(data)'は何を表示していますか?何かが本当にそこ –
は郵便配達にそれを行うか、どこか、チェックしてみてください、それは私が使用していたURLを表示すると 私はこれが返さ取得><返します 「[ を{ "Exercise_Id": "1"、 "Exercise_Name": "Barbell Curl"、 "Body_Part": "Arms" }、 ' –
私が試してみました印刷データである場合 – MHDev