Ios 将数据追加到多维数组(swift)

Ios 将数据追加到多维数组(swift),ios,arrays,swift,multidimensional-array,Ios,Arrays,Swift,Multidimensional Array,我在多维数组中传递数据时遇到问题。 这就是数组: var dataHome:[[String]] = [] 我想像这样把数据传给它: if let countries_list = json as? NSArray { for (var i = 0; i < countries_list.count ; i++ ) { if let country_obj = countries_list[i

我在多维数组中传递数据时遇到问题。 这就是数组:

var dataHome:[[String]] = []
我想像这样把数据传给它:

if let countries_list = json as? NSArray
        {
            for (var i = 0; i < countries_list.count ; i++ )
            {
                if let country_obj = countries_list[i] as? NSDictionary
                {

                    println(country_obj)
                    let countryName = country_obj["country"] as! String
                    let countryCode = country_obj["code"] as! String
                    var tempArray:[String] = []
                    tempArray.append(countryName)
                    tempArray.append(countryCode)

                    println(tempArray)
                    dataHome.append(tempArray)
                    println(dataHome)


                }
            }
        }
错误是:线程3:断点2.1
tempArray.append(countryName)

确切的错误消息是什么?这是真的发生在这条线上还是在一个强制展开的选项上?因为你的代码看起来不错。。。只要您始终拥有完整的数据,否则每次countryName或countryCode为零时它都会崩溃。我刚刚编辑了文章并添加了错误消息和完整的函数。请查看Xcode中突出显示行左侧的行号栏。如果有一个蓝色矩形,将其删除:它是一个断点。你可能是无意中设置了一个。你的答对了:D:D谢谢你的朋友!可能重复的
func extract_json(data:NSString){

    var parseError: NSError?
    let jsonData:NSData = data.dataUsingEncoding(NSASCIIStringEncoding)!
    let json: AnyObject? = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &parseError)

    if (parseError == nil)
    {
        if let countries_list = json as? NSArray
        {
            for (var i = 0; i < countries_list.count ; i++ )
            {
                if let country_obj = countries_list[i] as? NSDictionary
                {

                    println(country_obj)
                    var countryName = country_obj["country"] as! String
                    var countryCode = country_obj["code"] as! String
                    println(countryName)
                    println(countryCode)
                    var tempArray:[String] = []
                    tempArray.append(countryName)
                    tempArray.append(countryCode)

                    println(tempArray)
                    dataHome.append(tempArray)
                    println(dataHome)


                }
            }
        }
    }
    do_table_refresh();
}