I have the following JSON:
{ "registration": { "name": "Vik Kumar", "first_name": "Vik", "last_name": "Kumar", "bloodGroup": "B-", "gender": "male", "birthday": "10\/31\/1983", "email": "vik.ceo\u0040gmail.com", "cellPhone": "1234123456", "homePhone": "1234123457", "officePhone": "1234123458", "primaryAddress": "jdfjfgj", "area": "jfdjdfj", "location": { "name": "Redwood Shores, California", "id": 103107903062719 }, "subscribe": true, "eyePledge": false, "reference": "fgfgfgfg" } }
I use the following code to analyze it:
JsonNode json = new ObjectMapper().readTree(jsonString); JsonNode registration_fields = json.get("registration"); Iterator<String> fieldNames = registration_fields.getFieldNames(); while(fieldNames.hasNext()){ String fieldName = fieldNames.next(); String fieldValue = registration_fields.get(fieldName).asText(); System.out.println(fieldName+" : "+fieldValue); }
This works great and prints all values ββexcept the location, which is another level of nesting. I tried the same trick as above to pass json.get ("location"), but that doesn't work. Please suggest how to do this for the location.
Vik
source share