如何删除SwiftyJSON元素?

我有一个由SwiftyJSON生成的JSON数组(比如dataObj ),我尝试删除它的元素:

 let count=dataObj.count for var m=x; m<count; ++m { dataObj[m] = nil // there is no removeAtIndex() somehow } print(dataObj.count) print(dataObj) 

执行后, dataObj.count保持不变, print现在显示dataObj

[null,null,null,…]

真正删除SwiftyJSON元素的方法是什么?

最后我找到了删除由SwiftyJSON创建的JSON(数组类型)中的元素的答案:

 dataObj.arrayObject?.removeAtIndex(m) 

顺便说一句,当SwiftyJSON在字典类型中返回JSON时删除元素:

 jsonObj.dictionaryObject?.removeValueForKey(keyValue) 

更新Joe对Swift 4的回答。

从JSON中删除dictionary元素:

 json.dictionaryObject?.removeValue(forKey: key) 

从JSON中删除array元素:

 json.arrayObject?.remove(at: index)