我正在尝试使用SwiftyJSON从我的api中获取数据,但我从服务器收到此错误:
{"消息":"发生了错误。"}
我想处理它,但是当我想请求json时,我在这部分中遇到错误 我希望当服务器响应此结果时我什么都不做
func parsing(){
var URLString = server + "api/XXXXXX" + String(nextpage) + "&pagesize=10"
print(URLString)
guard let
URLString1 = URLString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
else {fatalError()}
let url = NSURL(string: URLString1)!
let task = NSURLSession.sharedSession().dataTaskWithURL(url) {(data, response, innerError) in
if let data = data where innerError == nil {
let jsonData1 = NSData(contentsOfURL: url) as NSData!
let readableJson = JSON(data: jsonData1, options: NSJSONReadingOptions.MutableContainers, error: nil)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.nrows = readableJson.count
for var i = 0 ; i < self.nrows ; i++ {
var json = readableJson[i]
let desc = json["Name"].string as String!
let iddesc = json["Id"].intValue//.string as String!
let groupName = json["Group_Name"].string as String!
let price1 = json["Price"].string as String!
}
}
}
}
task.resume()
}