JSON數組,這是從服務器我的PHP文件:解析圈穿過迅速
<?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);
?>
這就是我如何努力,以JSON數組從迅速
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()
應用崩潰內取在此行中let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
錯誤:
Could not cast value of type '__NSArrayM' (0x8c9b58) to 'NSDictionary' (0x8c9d74).
新來迅速和HTTP請求,所以不能完全小號這意味着什麼。