为什么Android的JSONArray中没有remove(int position)方法? [英] Why isn't there a remove(int position) method in Android's JSONArray?

查看:75
本文介绍了为什么Android的JSONArray中没有remove(int position)方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始构建一个使用平面文件进行存储的Android应用.该应用程序不会存储六个以上的记录,而且我对JSON很熟悉,因此我只在文件中写了JSONArray.

I started building an Android app that uses a flat file for storage. The app doesn't store more than six records, and I'm familiar with JSON, so I just write out a JSONArray to the file.

不过,我今天才发现,Android JSON API不包含remove()选项. ??我是否必须将数组转储到另一个集合中,将其删除,然后重新构建JSONArray?有什么意义?

I just discovered today, though, that the Android JSON API doesn't include a remove() option. Huh? Do I have to dump the array into another collection, remove it, then rebuild the JSONArray? What's the point?

推荐答案

重点是JSONArrayJSONObject旨在将数据反序列化为JSON,而不是操作数据. remove()方法似乎很有意义,但限制在哪里?您希望能够访问序列化对象上的属性吗?访问或更新嵌套数据结构?

The point is that JSONArray and JSONObject are meant to (de)serialize data to JSON, not manipulate data. A remove() method may seem to make sense, but where's the limit? Would you expect to be able to access attributes on serialized objects? Access or update nested data structures?

实际上,您的想法是您本地"操作数据结构.

The idea is, indeed, that you manipulate data structures "natively".

这篇关于为什么Android的JSONArray中没有remove(int position)方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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