This is the sample of a JSON object. I want to extract the part of it and display those values in a jTable (SWING) in JAVA. Keys as table column names and values as row data respectively.
[
{
"_id":{
"date":"xxxxxxxx",
"time":"xxxxxxx",
"inc":"xxxx"
},
"DOCUMENTS":[
{
"EName":"John",
"eAge":"25",
"eAddress":"UK"
},
{
"EName":"Alex",
"eAge":"24",
"eAddress":"Australia"
}
]
}
]
I want to extract this part.
[
{
"EName":"John",
"eAge":"25",
"eAddress":"UK"
},
{
"EName":"Alex",
"eAge":"24",
"eAddress":"Australia"
}
]
I used this way to get the answer. Here jsonstring is the string that contains above data.
String[] splits = jsonString.split("DOCUMENTS\":");
String[] splits2 = splits[1].split("\\}]", 2);
System.out.println("spilted :"+splits2[0]);
but it is giving me the answer as
[{"EName":"John","eAge":"25","eAddress":"UK"},
{"EName":"Alex","eAge":"24","eAddress":"Australia"
it removed the closed square bracket.
How can I get the correct answer? Your help is much appreciated.
DocumentsJSONArray?/0/DOCUMENTSit removed the closed square bracket- Since u split on "}]" -split2int len = split1[1].length(); String ans = split1[1].substring(0, len - 3); // assuming last 2 chars are ] and }