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
rebvijkumrebvijkum 

How to parse Json Response ?

Public Class ICS_WR_Warranty_Util{
	public static Boolean Processorfraudcheck(MAP<string,string> mapQryParameter)
    {
        ICS_WR_ConsumingPMFTData.ValidateProcessorResult   Response = ICS_WR_ConsumingPMFTData.get_ValidateProcessor_data(mapQryParameter);
        //string boxtray =response.BoxTrayIndicator;
		//Response = ValidateProcessorResult:[BoxTrayIndicator=Boxed, Last_Ship_To_Date=20101227000000, ProductFrequencyData=null, ProtectionPlanData=null, Rtl_Box_Manufacture_Dt=null, Rtl_Box_Mtrl_Id=null, Rtl_Box_SN=null, Rtl_Box_Site_Id=null, ShipmentInfo=ShipmentInfo:[ShipmentData=(ShipmentData:[AGIDDate=2010-12-08 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=KN0RW873, Level4Prod=CM8062300833803, MaterialMasterNumber=909498, ShipToCustomerCountryCode=US, ShipToCustomerCountryName=United States, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=SUB-MLMIA, ShipToCustomerName=MODUSLINK, VisualId=null], ShipmentData:[AGIDDate=2010-12-08 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=KN0RW872, Level4Prod=CM8062300833803, MaterialMasterNumber=909498, ShipToCustomerCountryCode=US, ShipToCustomerCountryName=United States, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=SUB-MLMIA, ShipToCustomerName=MODUSLINK, VisualId=null], ShipmentData:[AGIDDate=2010-12-22 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=null, Level4Prod=BX80623I52500K, MaterialMasterNumber=910679, ShipToCustomerCountryCode=US, ShipToCustomerCountryName=United States, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=0007011339, ShipToCustomerName=INGRAM US (CA) DSS, VisualId=null], ShipmentData:[AGIDDate=2010-12-23 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=null, Level4Prod=BX80623I52500K, MaterialMasterNumber=910679, ShipToCustomerCountryCode=US, ShipToCustomerCountryName=United States, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=0002002899, ShipToCustomerName=#10; FRYS, VisualId=null], ShipmentData:[AGIDDate=2010-12-23 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=null, Level4Prod=BX80623I52500K, MaterialMasterNumber=910679, ShipToCustomerCountryCode=US, ShipToCustomerCountryName=United States, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=0002002900, ShipToCustomerName=#11; FRYS, VisualId=null], ShipmentData:[AGIDDate=2010-12-27 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=null, Level4Prod=BX80623I52500K, MaterialMasterNumber=910679, ShipToCustomerCountryCode=CA, ShipToCustomerCountryName=Canada, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=0002002614, ShipToCustomerName=INGRAM MICRO CANADA INCORPORATED, VisualId=null], ShipmentData:[AGIDDate=2010-12-27 00:00:00, Batch=L040B436, BoxTrayIndicator=BOX, ChildBoxId=null, Level4Prod=BX80623I52500K, MaterialMasterNumber=910679, ShipToCustomerCountryCode=CA, ShipToCustomerCountryName=Canada, ShipToCustomerGeo=ASMO-NA, ShipToCustomerId=0002002614, ShipToCustomerName=INGRAM MICRO CANADA INCORPORATED, VisualId=null])], ValidationResultCodes=ValidationResultCodes:[ValidationResultCode=(ValidationResultCode:[Remarks=null, ValidationResultCodeId=27, ValidationResult_Code=PMFT-027])]]
        return null;
    }
}



Public class  ICS_WR_ConsumingPMFTData{
	public static ValidateProcessorResult get_ValidateProcessor_data(MAP<string,string> mapQryParameter)
   {
        if(mapQryParameter!=null &&mapQryParameter.keyset()!=null )
        {
            try
            {
                string processorOutpuFormat;
                if(mapQryParameter.containskey('FPO') && mapQryParameter.keyset().size()==1) // If only FPO passing as input parameter
                {
                processorOutpuFormat='{ "Last_Ship_To_Date": "20101227000000","BoxTrayIndicator": "Boxed", "ValidationResultCodes":{"ValidationResultCode" : [{"ValidationResultCodeId": "27","ValidationResult_Code": "PMFT-027"}]},"ShipmentInfo": {"ShipmentData": [{"Batch": "L040B436","MaterialMasterNumber": "909498","ChildBoxId": "KN0RW873","Level4Prod": "CM8062300833803","ShipToCustomerId": "SUB-MLMIA","ShipToCustomerName": "MODUSLINK","ShipToCustomerCountryCode": "US", "ShipToCustomerCountryName": "United States", "ShipToCustomerGeo": "ASMO-NA", "AGIDDate": "2010-12-08T00:00:00Z", "BoxTrayIndicator": "BOX"},{ "Batch": "L040B436", "MaterialMasterNumber": "909498", "ChildBoxId": "KN0RW872","Level4Prod": "CM8062300833803", "ShipToCustomerId": "SUB-MLMIA", "ShipToCustomerName": "MODUSLINK","ShipToCustomerCountryCode": "US","ShipToCustomerCountryName": "United States","ShipToCustomerGeo": "ASMO-NA","AGIDDate": "2010-12-08T00:00:00Z", "BoxTrayIndicator": "BOX"},{"Batch": "L040B436", "MaterialMasterNumber": "910679", "Level4Prod": "BX80623I52500K", "ShipToCustomerId": "0007011339","ShipToCustomerName": "INGRAM US (CA) DSS","ShipToCustomerCountryCode": "US", "ShipToCustomerCountryName": "United States", "ShipToCustomerGeo": "ASMO-NA","AGIDDate": "2010-12-22T00:00:00Z","BoxTrayIndicator": "BOX"},{ "Batch": "L040B436", "MaterialMasterNumber": "910679", "Level4Prod": "BX80623I52500K", "ShipToCustomerId": "0002002899", "ShipToCustomerName": "#10; FRYS", "ShipToCustomerCountryCode": "US",  "ShipToCustomerCountryName": "United States","ShipToCustomerGeo": "ASMO-NA", "AGIDDate": "2010-12-23T00:00:00Z", "BoxTrayIndicator": "BOX"}, { "Batch": "L040B436", "MaterialMasterNumber": "910679","Level4Prod": "BX80623I52500K", "ShipToCustomerId": "0002002900", "ShipToCustomerName": "#11; FRYS",  "ShipToCustomerCountryCode": "US",  "ShipToCustomerCountryName": "United States", "ShipToCustomerGeo": "ASMO-NA",  "AGIDDate": "2010-12-23T00:00:00Z",  "BoxTrayIndicator": "BOX" },{   "Batch": "L040B436","MaterialMasterNumber": "910679",  "Level4Prod": "BX80623I52500K",  "ShipToCustomerId": "0002002614", "ShipToCustomerName": "INGRAM MICRO CANADA INCORPORATED", "ShipToCustomerCountryCode": "CA","ShipToCustomerCountryName": "Canada", "ShipToCustomerGeo": "ASMO-NA", "AGIDDate": "2010-12-27T00:00:00Z", "BoxTrayIndicator": "BOX" },{ "Batch": "L040B436",  "MaterialMasterNumber": "910679","Level4Prod": "BX80623I52500K","ShipToCustomerId": "0002002614", "ShipToCustomerName": "INGRAM MICRO CANADA INCORPORATED", "ShipToCustomerCountryCode": "CA",  "ShipToCustomerCountryName": "Canada", "ShipToCustomerGeo": "ASMO-NA", "AGIDDate": "2010-12-27T00:00:00Z", "BoxTrayIndicator": "BOX" } ]}}';
                }
                else if(mapQryParameter.containskey('FPO') && mapQryParameter.containskey('ATPO')&& mapQryParameter.keyset().size()==2) //if FPO & ATPO passing as input parameter
                {
                    processorOutpuFormat='{"Rtl_Box_SN": "2V034116A2110","Rtl_Box_Site_Id": "CS79","Rtl_Box_Mtrl_Id": "910679","Rtl_Box_Manufacture_Dt": "20101220000000","Last_Ship_To_Date": "20101223000000","BoxTrayIndicator": "Boxed","ValidationResultCodes":{"ValidationResultCode" : [{"ValidationResultCodeId": "28","ValidationResult_Code": "PMFT-028"},{"ValidationResultCodeId": "27","ValidationResult_Code": "PMFT-027"},{"ValidationResultCodeId": "35","ValidationResult_Code": "PMFT-035"}]},"ShipmentInfo":{"ShipmentData": [{"Batch": "L040B436","VisualId": "2V034116A2110","MaterialMasterNumber": "910679","ChildBoxId": "96200200","Level4Prod": "BX80623I52500K","ShipToCustomerId": "0002002899","ShipToCustomerName": "#10; FRYS","ShipToCustomerCountryCode": "US","ShipToCustomerCountryName": "United States","ShipToCustomerGeo": "ASMO-NA","AGIDDate": "2010-12-23T00:00:00Z","BoxTrayIndicator": "BOX"}]}}';
                }
                else if(mapQryParameter.containskey('FPO') && mapQryParameter.containskey('PAC')&& mapQryParameter.keyset().size()==2) //if FPO & PAC passing as input parameter
                {
                    processorOutpuFormat='{"Rtl_Box_SN": "2V034116A2110","Rtl_Box_Site_Id": "CS79","Rtl_Box_Mtrl_Id": "910679","Rtl_Box_Manufacture_Dt": "20101220000000","Last_Ship_To_Date": "20101223000000","BoxTrayIndicator": "Boxed","ValidationResultCodes": {"ValidationResultCode" : [{"ValidationResultCodeId": "28","ValidationResult_Code": "PMFT-028"},{"ValidationResultCodeId": "27","ValidationResult_Code": "PMFT-027"},{"ValidationResultCodeId": "35","ValidationResult_Code": "PMFT-035"},{"ValidationResultCodeId": "101","ValidationResult_Code": "PTP-101","Remarks": "Plan is available and authenticated."}]},"ShipmentInfo": {"ShipmentData":[{"Batch": "L040B436","VisualId": "2V034116A2110","MaterialMasterNumber": "910679","ChildBoxId": "96200200","Level4Prod": "BX80623I52500K","ShipToCustomerId": "0002002899","ShipToCustomerName": "#10; FRYS","ShipToCustomerCountryCode": "US","ShipToCustomerCountryName": "United States","ShipToCustomerGeo": "ASMO-NA","AGIDDate": "2010-12-23T00:00:00Z","BoxTrayIndicator": "BOX"}]},"ProtectionPlanData": {"TransactionId": "24","TransactionDate": "20111111213805","SKU": "BX80623I52500K","PlanActivationCode": "000AB3EO","PlanEffectiveDate": "20111212213805","PaidByUserId": "cpsdtest13@gmail.com","PaidByUserFullName": "E D","LastOwnedByUserId": "cpsdtest01@gmail.com","LastOwnedByUserFullName": "CPSD Test"}}';
                }
                ValidateProcessorResult prData =new ValidateProcessorResult();
                prData=(ValidateProcessorResult)JSON.deserialize(processorOutpuFormat,ValidateProcessorResult.class); //De-serializing output json format
                system.debug('prData##'+prData) ;
                return prData;
            }
            Catch(Exception e)
            {
                isError=true;
            }
        }
        return null;
        
    }

	public class ValidateProcessorResult{
        public ShipmentInfo ShipmentInfo{get;set;}
        public String Last_Ship_To_Date{get;set;}
        public String Rtl_Box_Manufacture_Dt{get;set;}
        public String BoxTrayIndicator{get;set;}
        public String Rtl_Box_Mtrl_Id{get;set;}
        public ValidationResultCodes ValidationResultCodes{get;set;}
        public ProductFrequencyData ProductFrequencyData{get;set;}
        public String Rtl_Box_Site_Id{get;set;}
        public ProtectionPlanData ProtectionPlanData{get;set;}
        public String Rtl_Box_SN{get;set;}
        }
   
    public class ProductFrequencyData
    {
         public list<ProductFrequency> ProductFrequency{get;set;}
    }
    public class ValidationResultCodes
    {
         public list<ValidationResultCode> ValidationResultCode{get;set;}
    }
    public class ShipmentInfo{
        public list<ShipmentData> ShipmentData{get;set;}
        
    }
    public class ProductFrequency{
        public Integer FrequencyType{get;set;}
        public String FreqeuncyCount{get;set;}
    }
     public class ValidationResultCode {
        public String ValidationResult_Code{get;set;}
        public String ValidationResultCodeId{get;set;}
        public String Remarks{get;set;}
    }
    public class ShipmentData{
        public String ShipToCustomerCountryCode{get;set;}
        public String ShipToCustomerCountryName{get;set;}
        public String ShipToCustomerGeo{get;set;}
        public String ShipToCustomerName{get;set;}
        public DateTime AGIDDate{get;set;}
        public String ShipToCustomerId{get;set;}
        public String BoxTrayIndicator{get;set;}
        public String Level4Prod{get;set;}
        public String MaterialMasterNumber{get;set;}
        public String VisualId{get;set;}
        public String ChildBoxId{get;set;}
        public String Batch{get;set;}
    }
    public class ProtectionPlanData{
        public String SKU{get;set;}
        public String PaidByUserId{get;set;}
        public String PlanEffectiveDate{get;set;}
        public String PaidByUserFullName{get;set;}
        public String PlanActivationCode{get;set;}
        public String LastOwnedByUserId{get;set;}
        public String TransactionDate{get;set;}
        public String LastOwnedByUserFullName{get;set;}
        public Integer TransactionId{get;set;}
    }

}

I'm calling a method ICS_WR_ConsumingPMFTData.get_ValidateProcessor_data(mapQryParameter) and I get a deserialized Json response which I shown as a comment in the class. How can I read the response into different variables to use ?
pconpcon
I'm a little confused as to what the problem you are having is.  If you run the code with the deserialize, you should have the all the variables set.  I would read over these articles [1] [2].

[1] http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/
[2] http://blog.deadlypenguin.com/blog/2016/03/16/extending-objects-json-parsing/
rebvijkumrebvijkum
Thanks for the reply @pcon.
I still didn't get it. I know I shouldn't use string as datatype. But I wanted to show u what i need.
Here is the error: Error: Compile Error: Illegal assignment from ICS_WR_ConsumingPMFTData.ValidationResultCodes to String

public static Boolean Processorfraudcheck(MAP<string,string> mapQryParameter)
    {     
        ICS_WR_ConsumingPMFTData.ValidateProcessorResult   Response = ICS_WR_ConsumingPMFTData.get_ValidateProcessor_data(mapQryParameter);
        string vrc =response.ValidationResultCodes; // error on this line. how can i get the ValidationResultCodes
        return null;
    }