Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我想在swift 3中创建这种类型的数组_Ios_Arrays_Dictionary_Swift3_Nsdictionary - Fatal编程技术网

Ios 我想在swift 3中创建这种类型的数组

Ios 我想在swift 3中创建这种类型的数组,ios,arrays,dictionary,swift3,nsdictionary,Ios,Arrays,Dictionary,Swift3,Nsdictionary,我想在swift 3中的数组中创建这样类型的字典,我这样做了,但它不是方括号,而是方括号。我想要方括号中的字典 [{“兴趣id”:1},{“兴趣id”:2},{“兴趣id”:3}]您可以这样做: let dictArray = [ [ "interest_id":1 ] , ["interest_id":2], ["interest_id":3]] do { let jsonData = try JSONSerialization.data(withJSONObject

我想在swift 3中的数组中创建这样类型的字典,我这样做了,但它不是方括号,而是方括号。我想要方括号中的字典

[{“兴趣id”:1},{“兴趣id”:2},{“兴趣id”:3}]

您可以这样做:

let dictArray = [ [ "interest_id":1 ] , ["interest_id":2], ["interest_id":3]]

    do {
        let jsonData = try JSONSerialization.data(withJSONObject: dictArray, options: .prettyPrinted)
        let json = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)!
        print("json data: ", json )
    }
    catch {
        print("error: ", error.localizedDescription)
    }
您可以这样做:

let dictArray = [ [ "interest_id":1 ] , ["interest_id":2], ["interest_id":3]]

    do {
        let jsonData = try JSONSerialization.data(withJSONObject: dictArray, options: .prettyPrinted)
        let json = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)!
        print("json data: ", json )
    }
    catch {
        print("error: ", error.localizedDescription)
    }

您需要的是字典和数组的JSON表示。那是不同的。是的,我想要相同的json表示法。寻找
JSONSerialization
。你想要的是字典和数组的json表示法。这是不同的。是的,我想要相同的json表示。请查找
JSONSerialization