小编f1r*_*urf的帖子

无法将'__NSArrayM'(0x34df0900)类型的值转换为'NSDictionary'SWIFT

从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)

谢谢您的帮助

json web-services nsdictionary ios swift

11
推荐指数
2
解决办法
2万
查看次数

IOS9 - 无法使用类型'(String)'的参数列表调用'count'

我只是迁移到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)

string count swift ios9

10
推荐指数
1
解决办法
6687
查看次数

标签 统计

swift ×2

count ×1

ios ×1

ios9 ×1

json ×1

nsdictionary ×1

string ×1

web-services ×1