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请求,所以不能完全小号这意味着什么。