문제

Data present in LinkedHashMap:-

{
    contacts={
        id={
            version=6,
            lastUpdatedTimeStamp=1377,
            contactID=23,
            firstName=B,
            lastName=K
        }
    }
}

Here, "contacts" & "id" are objects.

I am able to get the values of "contacts" :

LinkedHashMap map = restClient.getLinkedHashMap();
Object contactObj = map.get("contacts");

But how to get the value of "firstName"?

Any help or guidance will be well appreciated.

도움이 되었습니까?

해결책

You should cast the contactObj to the class whose primitive you want to access. Ex, if your class for contactObj is Contact, then you should do:

Contact contactObj = (Contact) map.get("contacts");

and then you can access the methods/primitives in the class that are accessible from this point. Ex, say your class is like

Class Contact{
String firstname;
public String getFirstName(){
  return this.firstname;
   }
}  

So, you can access the first name like as shown below:

contactObj.getFirstName();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top