0

I want to fetch only PersonNumber value from below JSON sample using java.

{"Context":[{"PersonNumber":"10","DMLOperation":"UPDATE","PeriodType":"E","PersonName":"Ponce","WorkerType":"EMP","PersonId":"1000","PrimaryPhoneNumber":"1","EffectiveStartDate":"2018-01-27","EffectiveDate":"2018-01-27"}],"Changed Attributes":[{"NamInformation1":{"new":"Ponce","old":"PONCE"}},{"FirstName":{"new":"Jorge","old":"JORGE"}},{"LastName":{"new":"Ponce","old":"PONCE"}}]}

Below is my code:

for (SyndContentImpl content : (List<SyndContentImpl>) entry.getContents()) {
              
 JSONObject jsonObj = null;
  try {
      jsonObj = new JSONObject(content.getValue().toString());
      System.out.println(jsonObj.get("Context"));
    
      } catch (JSONException e) {
      e.printStackTrace();
  }  }

1 Answer 1

1

You have to access to the path Context[0].PersonNumber.

This can be done with

String personNumber = jsonObj.getJSONArray("Context").getJSONObject(0).getString("PersonNumber");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.