从webservice解码JSON响应时,我收到一条错误消息:
Could not cast value of type '__NSArrayM' (0x34df0900) to 'NSDictionary'
Run Code Online (Sandbox Code Playgroud)
我尝试了在StackOverflow中找到的很多解决方案,但没有任何效果.
我的代码:
let jsonData:NSDictionary = (NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as? NSDictionary)!
let success:NSInteger = jsonData.valueForKey("success") as! NSInteger
Run Code Online (Sandbox Code Playgroud)
来自Web服务的响应:
[
{
"id": "1",
"title": "bmw",
"price": "500.00",
"description": "330",
"addedDate": "2015-05-18 00:00:00",
"user_id": "1",
"user_name": "CANOVAS",
"user_zipCode": "32767",
"category_id": "1",
"category_label": "VEHICULES",
"subcategory_id": "2",
"subcategory_label": "Motos",
"bdd": {}
}
]
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助
我只是迁移到Xcode7/IOS9,我的部分代码不兼容.
我从Xcode得到以下错误:
"无法使用'(String)'类型的参数列表调用'count'"
这是我的代码:
let index = rgba.startIndex.advancedBy(1)
let hex = rgba.substringFromIndex(index)
let scanner = NSScanner(string: hex)
var hexValue: CUnsignedLongLong = 0
if scanner.scanHexLongLong(&hexValue)
{
if count(hex) == 6
{
red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0
green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0
blue = CGFloat(hexValue & 0x0000FF) / 255.0
}
else if count(hex) == 8
{
red = CGFloat((hexValue & 0xFF000000) >> 24) / 255.0
green = CGFloat((hexValue & 0x00FF0000) >> 16) / 255.0 …Run Code Online (Sandbox Code Playgroud)