我想在 swift 3 中创建这种类型的数组
i want to create such type of array in swift 3
我想在 swift 3 中的数组中创建这种类型的字典,我做到了,但它不是大括号,而是方形 bracket.i 想要大括号中的字典。
[ { "interest_id":1 } , {"interest_id":2}, {"interest_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)
}
我想在 swift 3 中的数组中创建这种类型的字典,我做到了,但它不是大括号,而是方形 bracket.i 想要大括号中的字典。
[ { "interest_id":1 } , {"interest_id":2}, {"interest_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)
}