用Gson随机写

时间:2015-05-20 09:25:59

标签: java json gson

我想知道是否有一种有效的方法
1。将额外信息写入现有的json文件?
2。从json数组中删除一个值?
我的Json文件:

[
    {"name": "A","age": 1,"sex": "male"},
    {"name": "B","age": 2,"sex": "female"},
    {"name": "C","age": 3,"sex": "male"}
]

如果我想将另一个值附加到json数组,

{"name": "D","age": 4,"sex": "female"}

如何在不重写整个json文件的情况下继续写入它?


预期结果将是:

    [
        {"name": "A","age": 1,"sex": "male"},
        {"name": "B","age": 2,"sex": "female"},
        {"name": "C","age": 3,"sex": "male"},
        {"name": "D","age": 4,"sex": "female"}
    ]

或者如果我想删除json数组中的字段

[
    {"name": "A","age": 1,"sex": "male"},
    {"name": "B","age": 2,"sex": "female"}
]

非常感谢。

0 个答案:

没有答案