var str = "[[1,2,3], [4,0,7], [5,6,8]]"
var digits: [[Int]]
如何在Swift中转换数字str?
答案 0 :(得分:0)
字符串看起来像一个json。尝试json解析。
let str = "[[1,2,3], [4,0,7], [5,6,8]]"
if let digits = (try? JSONSerialization.jsonObject(with: Data(str.utf8))) as? [[Int]] {
print(digits) //[[1, 2, 3], [4, 0, 7], [5, 6, 8]]
}