请教java字符串截取的问题

服务器返回的消息
第一种:
{"status":"1","function":"__VoicePrompt"}{"status":"0","function":"__StopNavigation"}

{"status":"23","function":"__VoicePrompt"}{"status":"0","function":"__StopNavigation"}

第二种:顺序会变
{"status":"0","function":"__StopNavigation"}{"status":"44","function":"__VoicePrompt"}

{"status":"0","function":"__StopNavigation"}{"status":"5","function":"__VoicePrompt"}

我想要的是,把包含__StopNavigation的大括号中的内容去掉,

只保留包含了__VoicePrompt的大括号中的内容--->{"status":"1","function":"__VoicePrompt"}

public static void main(String[] args) {
String str = "{\"status\":\"1\",\"function\":\"__VoicePrompt\"}{\"status\":\"0\",\"function\":\"__StopNavigation\"}";
JSONArray arr = JSONArray.fromObject("["+str.replaceAll("}","},")+"]");
for(int i=0;i<arr.size();i++){
JSONObject temp = arr.getJSONObject(i);
if(temp.containsValue("__StopNavigation")){
arr.remove(temp);
}
}
System.out.println(arr.toString().replaceAll("},","}").substring(1,arr.toString().length()-1));
}


可以转成JSON直接循环判断下不就可以了么。

你这个就是一个json格式的数据,json转object,你想处理什么数据都行