简体   繁体   中英

Remove a JSON object from a JSON string in Java

I have following JSON string:

[
{"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}
]

and I want to remove the whole second JSON object from my string (which has queueId:0). I have tried the .substring class but could not find any useful solutions for this purpose. Any suggestion ?.

If the string is in JSON format, you could just parse the json and store the string as a JSONArray and then remove the value with queueID = 0 from that. String manipulation on Strings in JSON format is not advised and can become complex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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