swift SwiftyJSON无法设置对象

时间:2016-01-13 18:12:04

标签: ios json swift

var petArray: JSON!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    var tmp: NSMutableArray!
    tmp = NSMutableArray()
    tmp.addObject(["name":"pet01", "age":15, "type":"dog", "breed":"QQ", "size":"small", "comment":"qqqq", "selected":0]);
    tmp.addObject(["name":"pet02", "age":15, "type":"dog", "breed":"QQ", "size":"small", "comment":"wwww", "selected":0]);

    petArray = JSON(tmp)

    petArray[0]["name"] = JSON("QQQQ") //why cannot update????

    print(petArray)
}

我尝试在第一个索引处更新名称,但没有用

如果出错了?

1 个答案:

答案 0 :(得分:0)

在转换为JSON之前,您必须更新它。