package com.inlet.ifserver;
import com.filethis.common.util.JsonEncodeDecode;
import java.util.Map;
import java.util.List;
public class x {
static String json = "[\n"+
" {\n"+
" \"text\": \"abcdef\",\n"+
" \"id\": \"369-03\",\n"+
" \"tags\": [\n"+
" {\n"+
" \"id\": \"P0\",\n"+
" \"start\": \"16\",\n"+
" \"end\": \"26\",\n"+
" \"text\": \"2080-11-30\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"DATE\",\n"+
" \"type\": \"Date\"\n"+
" },\n"+
" {\n"+
" \"id\": \"P1\",\n"+
" \"start\": \"48\",\n"+
" \"end\": \"52\",\n"+
" \"text\": \"Owen\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"NAME\",\n"+
" \"type\": \"PATIENT\"\n"+
" },\n"+
" {\n"+
" \"id\": \"P5\",\n"+
" \"start\": \"1664\",\n"+
" \"end\": \"1683\",\n"+
" \"text\": \"William Seth Potter\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"NAME\",\n"+
" \"type\": \"Name\"\n"+
" },\n"+
" {\n"+
" \"id\": \"P2\",\n"+
" \"start\": \"58\",\n"+
" \"end\": \"60\",\n"+
" \"text\": \"63\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"AGE\",\n"+
" \"type\": \"AGE\"\n"+
" }\n"+
" ]\n"+
" },\n"+
" {\n"+
" \"text\": \"12345\",\n"+
" \"id\": \"354-02\",\n"+
" \"tags\": [\n"+
" {\n"+
" \"id\": \"P0\",\n"+
" \"start\": \"16\",\n"+
" \"end\": \"26\",\n"+
" \"text\": \"2095-09-04\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"DATE\",\n"+
" \"type\": \"Date\"\n"+
" },\n"+
" {\n"+
" \"id\": \"P11\",\n"+
" \"start\": \"3020\",\n"+
" \"end\": \"3023\",\n"+
" \"text\": \"CCH\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"LOCATION\",\n"+
" \"type\": \"HOSPITAL\"\n"+
" },\n"+
" {\n"+
" \"id\": \"P12\",\n"+
" \"start\": \"3238\",\n"+
" \"end\": \"3240\",\n"+
" \"text\": \"GH\",\n"+
" \"comment\": \"\",\n"+
" \"category\": \"LOCATION\",\n"+
" \"type\": \"HOSPITAL\"\n"+
" }\n"+
" ]\n"+
" }\n"+
"]";
public static void main(String[] args) {
List<Map<String, Object>> data = (List<Map<String, Object>>) JsonEncodeDecode.decode(json);
for (Map<String, Object> entry : data) {
List<Map<String, String>> tags = (List<Map<String, String>>)entry.get("tags");
for (int i = tags.size() ; i > 0 ; i--) {
Map<String, String> tag = tags.get(i-1);
if (tag.get("type").equals("Date")) {
System.out.println("Deleting record with id: " + tag.get("id"));
tags.remove(i-1);
}
}
}
System.out.println(JsonEncodeDecode.encode(data, true));
}
}
Выходы:
Deleting record with id: P0
Deleting record with id: P0
[ {
"text" : "abcdef",
"id" : "369-03",
"tags" : [ {
"id" : "P1",
"start" : "48",
"end" : "52",
"text" : "Owen",
"comment" : "",
"category" : "NAME",
"type" : "PATIENT"
}, {
"id" : "P5",
"start" : "1664",
"end" : "1683",
"text" : "William Seth Potter",
"comment" : "",
"category" : "NAME",
"type" : "Name"
}, {
"id" : "P2",
"start" : "58",
"end" : "60",
"text" : "63",
"comment" : "",
"category" : "AGE",
"type" : "AGE"
} ]
}, {
"text" : "12345",
"id" : "354-02",
"tags" : [ {
"id" : "P11",
"start" : "3020",
"end" : "3023",
"text" : "CCH",
"comment" : "",
"category" : "LOCATION",
"type" : "HOSPITAL"
}, {
"id" : "P12",
"start" : "3238",
"end" : "3240",
"text" : "GH",
"comment" : "",
"category" : "LOCATION",
"type" : "HOSPITAL"
} ]
} ]