function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saurabh Kulkarni 26Saurabh Kulkarni 26 

Accessing Inner class variables

Hello all, 

I have a class structure like below:
 
Public void MainClass {
     Public String a;
     Public Strnig b;
     Public void SubClass{
          Public String x;
          Public String y;
      }
}

I'm Using this class to deserelize JSON. Once I deserelize I'm getting all the details in MainClass instance.
For eg:
JSONPareser jp = (JSONPareser) JSON.deserelize(JSONString,JSONParser.class);
jp object contains value of all the variables.
Now, I want to access value of x and y variables. How could I do that?? 
I'm only able to access jp.a and jp.b ..... What can be done to access x and y..

Thanks in advance 
Saurabh
B TulasiB Tulasi

Hi   Saurabh,
 
     Yes, we can acces through reference variable, otherwise we can't passible to access that variables. mean there is no otherway.
Thanks
Thulasi
AK2017AK2017
i am in the same situation. I am parsing a Json and all my variables are in inner class. how to get that from outer class?
Saurabh Kulkarni 26Saurabh Kulkarni 26
You need to simply do something just like this: JSONPareser jp = (JSONPareser) JSON.deserelize(JSONString,JSONParser.class); MainClass.SubClass subcls = new MainClass.SubClass(); Subcls = jp.SubClass; String myXstr = Subcls.X; String myYstr = Subcls.Y; Regards, Saurabh Kulkarni