0

I have a JSON Object as below:

{  
   "_embedded":{  
      "user":{  
         "passwordChanged":"01/10/2017",
         "profile":{  
            "firstName":"xyz",
            "lastName":"abc",
            "timeZone":"America/Los_Angeles",
            "login":"xyz@abc.com",
            "locale":"en"
         },
         "id":"1234567a"
      }
   },
   "token":"120392w",
   "expiresAt":"01/12/2022",
   "status":"active"
}

I want to iterate this object and retrieve the value of "timeZone". How do I do it in JAVA?

mack
  • 345
  • 5
  • 18

1 Answers1

0

Use gson to parse the json to a class:

    Gson gson = new GsonBuilder.create();
    UserData userData = gson.fromJson("your json here",UserData.class);
    System.out.println(userData.get_embeded().getUser().getProfile().getTimeZone());

Note that you'll have to create the class you are parsing the json to.

Fernando Bravo Diaz
  • 551
  • 1
  • 4
  • 11