I wanted to get element value at specific position using keys. For example :: I want to get value for
- personalDetails.name
- products[1].productName
- products[1].productPrice
when i try to fetch the value from jsonobject using
JsonElement el = JsonParser.parseString(json);
JsonObject object=el.getAsJsonObject();
object.get("personalDetails.name"); // I get value as null
object.get("products[1].productName"); // I get value as null
I did try different approaches like /products/1/productName , /personalDetails/name, but it dosent work.
My json looks like
{
"accountNumber": "9876543215345353453453453454",
"amount": "$49",
"personalDetails": {
"name": "ankit ostwal"
},
"products": [{
"productName": "watch",
"productPrice": "$21"
}, {
"productName": "belt",
"productPrice": "$4"
}, {
"productName": "belt",
"productPrice": "$4"
}]
}
Let me know if anyone can help. Thanks.