this is my php file from a server:
<?php
$results = Array(
Array(
"name" => "William",
"location" => "UK",
"action" => "Post Update"
),
Array(
"name" => "Sammy",
"location" => "US",
"action" => "posted news"
)
);
header("Content-Type: application/json");
echo json_encode($results);
?>
And this is how I try to fetch the json array from within swift
let urlPath = "http://someurltophpserver"
let url = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in
if ((error) != nil) {
println("Error")
} else {
let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
// do something with the data
}
})
task.resume()
The app crashes in this line let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary with error:
Could not cast value of type '__NSArrayM' (0x8c9b58) to 'NSDictionary' (0x8c9d74).
New to swift and http request, so not entirely sure what this means.