如何删除 SwiftyJSON 元素? [英] How to remove a SwiftyJSON element?

查看:43
本文介绍了如何删除 SwiftyJSON 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a JSON array (say, dataObj) generated by SwiftyJSON and I try to remove its element like this:

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变成

After execution, dataObj.count remains the same and print shows now dataObj becomes

[空,空值,空值,...]

[null, null, null, ... ]

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

What's the way to really remove an element for SwiftyJSON?

推荐答案

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

Finally I found the answer to remove an element in JSON (array type) created by SwiftyJSON:

dataObj.arrayObject?.removeAtIndex(m)

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

By the way, to remove an element when JSON returned by SwiftyJSON in a dictionary type:

jsonObj.dictionaryObject?.removeValueForKey(keyValue)

更新

斯威夫特 3+ -

数组:

dataObj.arrayObject?.remove(at: m)

字典:

jsonObj.dictionaryObject?.removeValue(forKey: keyValue)

这篇关于如何删除 SwiftyJSON 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆