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
Varsha D 9Varsha D 9 

desearilaization the json data

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://demo1691926.mockable.io/Api12');
req.setHeader('Content-Type', 'application/json');
HttpResponse response = h.send(req);
system.debug('response  : '+response.getBody());
String json1= response.getBody();
DesearlizingJson desearilize1=(DesearlizingJson) Json.deserialize(json1,DesearlizingJson.Class);
System.debug('Phone is' +desearilize1.phone);
System.debug('name  is' +desearilize1.name);


Wrapper class
public class DesearlizingJson {
    public Decimal phone;
    public String name;
    public Decimal mobile;

}
json:
{
 "Phone":75645433221,
 "name":"var",
 "mobile":8766555544
 }
ouput is:
phone is :87675565
name is  : varsha


i need help how to retrieve (i,e Expected output:)
phone:8898999
name:varsha 

i,e how to retrive both key and its corresponding value in debug log

Thanks in Advance 
 
Best Answer chosen by Varsha D 9
Suraj Tripathi 47Suraj Tripathi 47

Hi,

You can take references from the below code.

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://demo1691926.mockable.io/Api12');
req.setHeader('Content-Type', 'application/json');
HttpResponse response = h.send(req);
system.debug('response  : '+response.getBody());
String json1= response.getBody();
 Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(json1);
        system.debug('results::'+results);
         for(String str:results.keySet()){
           system.debug('str::'+results.get(str)); 
        }
        system.debug('Phone:::::'+results.get('Phone'));

Please mark it as the Best Answer so that other people would take references from it.

Thank You