Json Swift分析错误/强制转换异常

Json Swift分析错误/强制转换异常,json,parsing,swift,casting,Json,Parsing,Swift,Casting,我正在尝试用swift解析JSON。在我之前的程序中,当我说 func connectionDidFinishLoading(connection: NSURLConnection!) { var err: NSError // throwing an error on the line below (can't figure out where the error message is) var jsonResult: NSDictionary = NSJSONSeri

我正在尝试用swift解析JSON。在我之前的程序中,当我说

func connectionDidFinishLoading(connection: NSURLConnection!) {
    var err: NSError
    // throwing an error on the line below (can't figure out where the error message is)
    var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary

    println(jsonResult.valueForKey("results")?.valueForKey("geometry")?.valueForKey("location")?.valueForKey("lat"))

    if(jsonResult.valueForKey("status") as String == "OK"){
        var nearestLat = jsonResult.valueForKey("results")?.valueForKey("geometry")?.valueForKey("location")?.valueForKey("lat") as [CLLocationDegrees]
        var nearestLong = jsonResult.valueForKey("results")?.valueForKey("geometry")?.valueForKey("location")?.valueForKey("lng") as [CLLocationDegrees]
        var openStatus = jsonResult.valueForKey("results")?.valueForKey("opening_hours")?.valueForKey("open_now") as [Int]
        var address = jsonResult.valueForKey("results")?.valueForKey("vicinity") as [String]
        var name = jsonResult.valueForKey("results")?.valueForKey("name") as [String]

        var boolOpen = Bool(openStatus[0])

        var nearestChipotle = NearestRestaurant(name: name[0], lat: nearestLat[0], long: nearestLong[0], address: address[0], open: boolOpen)

        println(nearestChipotle.milesToRestuarant(self.latitude, fromLong: self.longitude))
//            
//            println(nearestLat[0])
//            println(nearestLong[0])
//            println(boolOpen)
//            println(address[0])
//            println(name[0])

    }

    else if jsonResult.valueForKey("status") as String == "ZERO_RESULTS"{
        println("NO CHIPOTLE!")
    }
不起作用

if(jsonResult.valueForKey("status") as String == "OK"){

        println(jsonResult.valueForKey("rows")?.valueForKey("elements")?.valueForKey("distance")?.valueForKey("text") as String)
       //var metersTo = jsonResult.valueForKey("rows")?.valueForKey("elements")?.valueForKey("distance")?.valueForKey("value") as String
        //println(metersTo)
       //self.distanceTo = metersToMiles()
       //println(self.distanceTo)
       //self.timeTo = jsonResult.valueForKey("rows")?.valueForKey("elements")?.valueForKey("duration")?.valueForKey("text") as String

        //println(metersTo)
        //println(self.timeTo)
    }

    else if jsonResult.valueForKey("status") as String == "ZERO_RESULTS"{
        println("NO DISTANCE COMPUTED!")
    }
但当我稍后在程序中尝试同样的方法时,我得到了这个错误

由该代码引起的

下面是我的输出。看起来我得到的第二个JSON由于额外的括号无法正确转换。

有没有办法处理这些括号,或者是什么原因造成的


这两个JSON信息都来自Google API

请将您的真实代码添加为[Int}不会编译!也不会作为屏幕截图。-如果您有一个具有意外结果的深度链接表达式,为什么不将其拆分为单独的连续赋值,并检查每个中间结果?然后您可以看到它没有按预期工作的地方。这是完整的代码。