I am trying to parse nested Json
with duplicate keys in Java . I've went through other similar questions but am unable to find a solution.I tried an approach using the Jackson streaming API but it only prints the value of the first key and ignores the second duplicate key. Please help.Thanks in advance.
Code:
public class JacksonJson {
public static void main(String args[]) throws IOException {
/
JsonFactory factory = new JsonFactory();
JsonParser parser = factory.createParser(new File("a.json"));
parser.nextToken();
while (parser.nextToken() != JsonToken.END_OBJECT) { //loop until "}"
String fieldName = parser.getCurrentName();
if (fieldName.equals("A")) {
parser.nextToken();
System.out.println("Value : " + parser.getText());
}
/*else { // unexpected token, generate error
throw new IOException("Unrecognized field '"+fieldName+"'");
}*/
}
parser.close();
}
}
Json file:
{
"Data": {
"C": {
"S": {
"M": {},
"A": "first"
}
},
"C": {
"S": {
"M": {}
"A": "Second",
}
}
}
}