简体   繁体   English

如何在Swift中从JSON数组中删除项目(使用SwiftyJSON)

[英]How to remove an item from JSON array in Swift (using SwiftyJSON)

Pretty simple and straightforward question. 非常简单明了的问题。

I have a jsonArray, and i want to delete an item by index. 我有一个jsonArray,我想按索引删除一个项目。 How do I do that? 我怎么做?

I tried using the solution from here: https://github.com/SwiftyJSON/SwiftyJSON/issues/439 我尝试从这里使用解决方案: https : //github.com/SwiftyJSON/SwiftyJSON/issues/439

Like this: 像这样:

jsonArray[row]["Likers"].array!.dictionaryObject?.removeValueForKey(index)

But I got this error: 但是我得到了这个错误:

value of type json has no member dictionaryObject

Finally I found the answer to remove an element in JSON (array type) created by SwiftyJSON: 最后,我找到了删除SwiftyJSON创建的JSON(数组类型)中的元素的答案:

dataObj.arrayObject?.removeAtIndex(m)

By the way, to remove an element when JSON returned by SwiftyJSON in a dictionary type: 顺便说一句,当SwiftyJSON以字典类型返回JSON时,要删除一个元素:

jsonObj.dictionaryObject?.removeValueForKey(keyValue)

I'm getting this answer form THIS 我得到这个答案形成

you just use 你只用

yourJsonArry.removeAtIndex(2) 

Hear you just pass the index that you want to remove items 听到您只是通过要删除项目的索引

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM