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
NSK000NSK000 

How to get data from JSON into salesforce

I need to get the data from JSON into salesforce object(custom object).  
Following is the JSON - 
{"EMPL_TYPE":" ","GRADE":"19","STD_HOURS":40.00,"EMPLID":"JCSD"}

I have a custom object in salesforce and I need to get the above values into their respective fields when i click a button on the custom object.
My code is as follows-

public class Empdetails {
public String EMPL_TYPE;
public String GRADE;
public Double STD_HOURS;
public String EMPLID;
public static Empdetails parse(String EMPLID) {
        Http httpProtocol = new Http();
        HttpRequest request = new HttpRequest(); 
        request.setEndpoint('xyz'+EMPLID);
        request.setMethod('GET'); 
        HttpResponse response = httpProtocol.send(request);
        system.debug(response.getBody());
        String jsonString = response.getBody();
        // Parse JSON response to get all the Employee record details
        JSONParser parser = JSON.createParser(response.getBody());
        return (Empdetails) System.JSON.deserialize(EMPLID, Empdetails.class);
    }
}

Actually I'm new to this concept. Am I doing correct ? Please suggest me some inputs.
Thank you
Raj VakatiRaj Vakati
Yes. that is the correct and easy way. 
Raj VakatiRaj Vakati
Refer some of the blogs and other options 
https://wedgecommerce.com/json-parsing-salesforce/
http://blog.adityanaag.com/22/Parsing+JSON+the+easy+way+using+Apex
http://salesforce-walker.blogspot.com/2013/08/json-parser-example.html
http://www.sfdcstuff.com/2015/06/parsing-json-in-apex.html
http://www.salesforcenextgen.com/how-to-do-json-parsing-of-a-wrapper-class-in-salesforce/
https://github.com/Trigger2991/SFDC-JSON-Parser
NSK000NSK000
Thank you Raj for your response. 
Do you have any idea how to call this class using a button? 
 
Raj VakatiRaj Vakati
Yes ... You can do it in two ways. 
  1. Create a visual force page and call the class as controller 
  2. Create a javascript button using AJAX API and call from the button click