+ Start a Discussion
code developercode developer 

JSON Response map with Apex Classes

Hi,

 

I am getting Json response from an api callout as shown below:

 

{"hint":"value"}.

 

In order to deserialize the json to my apex class, I have to declare a String variable hint,but hint is a reserved keyword.So, how should I map this json to my apex? please help me out.

sfdcfoxsfdcfox

I don't have a direct answer for this, but would it be possible to deserialize to a map instead?

 

map< string, string > values = (map< string, string >)json.deserialize(jsonString,map< string, string >.class);

From here, you can use:

 

values.get('hint')

To get the value of hint (e.g. "value"). Or, use a JSONParser instead, but this might be more tedious...

 

Edit: OR...

 

You can also use deserializeUntyped to get a Map< String, Object >, which you can use to get at "hint" directly. See the documentation for details.