samedi 16 juillet 2016

Match Two Nested Json String in Java

I have two json string data having nested key values. I have no idea what will be in that strings. Means I can't use any java class to map these key and values.

Fg:

{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
    {
        "batter":
            [
                { "id": "1001", "type": "Regular" },
                { "id": "1002", "type": "Chocolate" },
                { "id": "1003", "type": "Blueberry" },
                { "id": "1004", "type": "Devil's Food" }
            ]
    },
"topping":
    [
        { "id": "5001", "type": "None" },
        { "id": "5002", "type": "Glazed" },
        { "id": "5005", "type": "Sugar" },
        { "id": "5007", "type": "Powdered Sugar" },
        { "id": "5006", "type": "Chocolate with Sprinkles" },
        { "id": "5003", "type": "Chocolate" },
        { "id": "5004", "type": "Maple" }
    ]

}

If I have tow string as above and if "id" has 0001 & 0002 and "name" has cake & cookie. then I need

FIELD [id] Expected=0001 Actual=0002 , Matched FIELD [name] Expected=cake Actual=cake. Not Matched.

Thanks

Aucun commentaire:

Enregistrer un commentaire