Sample Code:
Contact con = new Contact(FirstName = 'First', LastName = 'Last', Phone = '9999999999', Email = 'Test@test.com');
/* Code to convert Contact to JSON string */
String strJSON = JSON.serialize(con);
system.debug('JSON String is ' + strJSON);
/* Code to convert JSON string to Contact */
Contact con1 = (Contact)JSON.deserialize(strJSON, Contact.Class);
system.debug('Contact is ' + con1);
Output:
Contact con = new Contact(FirstName = 'First', LastName = 'Last', Phone = '9999999999', Email = 'Test@test.com');
/* Code to convert Contact to JSON string */
String strJSON = JSON.serialize(con);
system.debug('JSON String is ' + strJSON);
/* Code to convert JSON string to Contact */
Contact con1 = (Contact)JSON.deserialize(strJSON, Contact.Class);
system.debug('Contact is ' + con1);
Output:
No comments:
Post a Comment