Working With Json in Apex
Working With Json in Apex
Today we will learn few of the JSON method which we use frequently in
our day-to-day life coding:
1. JSON.deserialize():
Decimal n = (Decimal)JSON.deserialize(
'100.1', Decimal.class);
System.assertEquals(n, 100.1);
2. JSON. deserializeStrict():
'{"Name":"Sweety","Gender":"Female"}',
Student.class);
System.assertEquals(student.Name, Sweety);
System.assertEquals(student.Gender, Female);
3. JSON.deserializeUntyped() :
We have JSON :
Ex1 : {
"Detail": "Accounts",
"data": {
"name": Abc,
"Amount": 40000
}
Ex2 :
"detail": {
"object": "Account",
"ChildRelationship": "Contacts"
},
"data": {
"status": Open
JSON input that varies in this way cannot be handled with strongly
typed Apex classes because its structure is not uniform. The
values for the keys detail and data have different types.