Why do I get the error 'Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}'?
<p>I am new to Swift and iOS development but I am trying to download and parse data that is stored in a MySQL Database. </p>

<p>I keep getting the error:</p>

<blockquote>
  <p>Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}</p>
</blockquote>

<p>I have posted my code below but I don't think the problem is in the parseJSON function but instead in the actual download of the data as when I print the 'data' out it returns '&lt;>'.</p>

<p>Here is my code:</p>

<pre><code>//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 ..&lt; 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: { () -&gt; Void in

        self.delegate.itemsDownloaded(items:locations)

    })
}
</code></pre>