Swift - Invalid value around character 0
<p>I know this has been answered, but the answers on here for this error have not helped yet.</p>

<p>I'm trying to get data from a server and put it in a table view, but it won't show up. I have this piece of code that determines whether data is received:</p>

<pre><code>func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
        if error != nil {
            print("Failed to download data")
        }else {
            print("Data downloaded")
            self.parseJSON()
        }
    }
</code></pre>

<p>but it does not work. The output from the console is:</p>

<pre><code> Data downloaded
Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}
</code></pre>

<p>So why does the data say it is downloaded but then I get an error? My url is definitely correct.</p>

<p>This is my parseJSON function:</p>

<pre><code>func parseJSON() {

    var jsonResult: NSMutableArray = NSMutableArray()

    do{
        jsonResult = try NSJSONSerialization.JSONObjectWithData(self.data, options:NSJSONReadingOptions.AllowFragments) as! NSMutableArray

    } catch let error as NSError {
        print(error)

    }

    var jsonElement: NSDictionary = NSDictionary()
    let locations: NSMutableArray = NSMutableArray()

    for(var i = 0; i &lt; jsonResult.count; i++)
    {

        jsonElement = jsonResult[i] as! NSDictionary

        let location = LocationModel()

        //the following insures none of the JsonElement values are nil through optional binding
        if let accented = jsonElement["Accented"] as? String,
            let unaccented = jsonElement["Unaccented"] as? String
        {

            location.accented = accented
            location.unaccented = unaccented

        }

        locations.addObject(location)

    }

    dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in

        self.delegate.itemsDownloaded(locations)

    })
}
</code></pre>

<p>Here's the data from the server:</p>

<pre><code>&lt;html&gt;\n&lt;head&gt;\n&lt;meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"&gt;\n&lt;/head&gt;\n&lt;body&gt;\n[{\"id\":\"1\",\"accented\":\"mē\",\"unaccented\":\"me\"},{\"id\":\"2\",\"accented\":\"quid\",\"unaccented\":\"quid\"},{\"id\":\"3\",\"accented\":\"nihil\",\"unaccented\":\"nihil\"},{\"id\":\"4\",\"accented\":\"nōn\",\"unaccented\":\"non\"},{\"id\":\"5\",\"accented\":\"saepe\",\"unaccented\":\"saepe\"},{\"id\":\"6\",\"accented\":\"sī\",\"unaccented\":\"si\"},{\"id\":\"7\",\"accented\":\"amō, amāre, amāvī, amātum\",\"unaccented\":\"amo\"},{\"id\":\"8\",\"accented\":\"amābō tē\",\"unaccented\":\"amabo te\"},{\"id\":\"9\",\"accented\":\"cōgitō, cōgitāre, cōgitāvī, cōgitātum\",\"unaccented\":\"cogito\"},{\"id\":\"10\",\"accented\":\"dēbeō, dēbēre, dēbuī, dēbitum\",\"unaccented\":\"debeo\"},{\"id\":\"11\",\"accented\":\"dō, dare, dedī, datum\",\"unaccented\":\"do\"},{\"id\":\"12\",\"accented\":\"errō, errāre, errāvī, errātum\",\"unaccented\":\"erro\"},{\"id\":\"13\",\"accented\":\"laudō, laudāre, laudāvī, laudātum\",\"unaccented\":\"laudo\"},{\"id\":\"14\",\"accented\":\"moneō, monēre, monuī, monitum\",\"unaccented\":\"moneo\"},{\"id\":\"15\",\"accented\":\"salveō, salvēre\",\"unaccented\":\"salveo\"},{\"id\":\"16\",\"accented\":\"salvē, salvēte\",\"unaccented\":\"salve\"},{\"id\":\"17\",\"accented\":\"servō, servāre, servāvī, servātum\",\"unaccented\":\"servo\"},{\"id\":\"18\",\"accented\":\"cōnservō, cōnservāre, cōnservāvī, cōnservātum\",\"unaccented\":\"conservo\"},{\"id\":\"19\",\"accented\":\"terreō, terrēre, terruī, territum\",\"unaccented\":\"terreo\"},{\"id\":\"20\",\"accented\":\"valeō, valēre, valuī, valitūrum\",\"unaccented\":\"valeo\"},{\"id\":\"21\",\"accented\":\"valē, valēte\",\"unaccented\":\"vale\"},{\"id\":\"22\",\"accented\":\"videō, vidēre, vīdī, vīsum\",\"unaccented\":\"video\"},{\"id\":\"23\",\"accented\":\"vocō, vocāre, vocāvī, vocātum\",\"unaccented\":\"voco\"}]&lt;/body&gt;\n&lt;/html&gt;
</code></pre>