Friday, August 4, 2017

Parse the JSON Response in Salesforce Apex -Part 1

In this post I'm going to explain how to create a Wrapper class to Parse the JSON Response in Apex which contains key and value pair in JSON.

JSON String:

 "status": "SUCCESS",
 "errors": [],
 "data": {
  "oldCaseStatus": "Case_CANCELLATION_success",
  "newCaseStatus": "Case_CANCELLATION_success",
  "NewCaseNumber": "3732gy12"

Apex Class:

public class ParsingTest
  public ParsingTest()
      String json='{"status":"SUCCESS","errors":[],"data":{"oldCaseStatus":"Case_CANCELLATION_success","newCaseStatus":"Case_CANCELLATION_success","NewCaseNumber":"3732gy12"}}';
      ParsingWrapper apiRespone = new ParsingWrapper();
      apiRespone = (ParsingWrapper)System.JSON.deserialize(json,ParsingWrapper.class);

 //Wrapper Class For Parsering 

  public class ParsingWrapper
   public String status{get;set;}
   public Map<String,String> data{get;set;}
   public Cls_errors[] errors;

  public class Cls_errors


Hope this helps you....Enjoy!

No comments:

Post a Comment