从Java中的JSON字符串中删除JSON对象

时间:2014-05-08 15:17:18

标签: java json

我有以下JSON字符串:

[
{"portNumber":3,"queueId":1,"transmitBytes":0,"transmitPackets":0,"transmitErrors":0},
{"portNumber":2,"queueId":0,"transmitBytes":12940,"transmitPackets":199,"transmitErrors":0},
{"portNumber":2,"queueId":1,"transmitBytes":70,"transmitPackets":1,"transmitErrors":0},
{"portNumber":2,"queueId":2,"transmitBytes":0,"transmitPackets":0,"transmitErrors":0}
]

我想从我的字符串(其queueId:0)中删除整个第二个JSON对象。我已经尝试过.substring类但是找不到任何有用的解决方案。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

如果字符串是JSON格式,您可以解析json并将字符串存储为JSONArray,然后从中删除queueID = 0的值。不建议使用JSON格式的字符串操作,并且可能会变得复杂。