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
EQ AdminEQ Admin 

Need help in deserializing JSON list of input to my weservice

Web Service : 

global class APTS_UsageInputWS {
    global static void loadUsageInputs ()
        RestRequest req =RestContext.request;
           Blob body = req.requestBody;
           String requestString = body.toString();
        APTS_UsageInputWrapper inputList = (APTS_UsageInputWrapper)JSON.deserialize(requestString,APTS_UsageInputWrapper.class);
        List<EQ_TempSSP1Data__c> tempData = new List<EQ_TempSSP1Data__c>();
            delete [select id from EQ_TempSSP1Data__c];
            Integer counter = 1;
            for(APTS_UsageInputWrapperData record :
                tempData.add(new EQ_TempSSP1Data__c(EQ_WorkId__c = inputList.EQ_WorkId,
                            EQ_SourceSystem__c = record.EQ_SourceSystem,
                            EQ_IssueNumber__c = record.EQ_IssueNumber,
                            EQ_ServiceCode__c = record.EQ_ServiceCode,
                            EQ_Quantity__c = record.EQ_Quantity,
                            EQ_QuantityID__c = record.EQ_QuantityID,
                            EQ_RecordKey__c = record.EQ_RecordKey,
                            EQ_LoadMonth__c = Date.newInstance(Integer.valueOf(record.EQ_LoadMonth.left(4)), Integer.valueOf(record.EQ_LoadMonth.subString(4,5)), Integer.valueOf(record.EQ_LoadMonth.subString(6,7))),            
                            Name = counter + '-' + record.EQ_LoadMonth + '-' + record.EQ_IssueNumber));
            insert tempData;
            system.debug('validation called%%%%');

JSON input:


While calling service from workbecnh getting error:

message: System.JSONException: Unexpected character ('F' (code 70)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:4, column:18] Class.System.JSON.deserialize: line 15, column 1 Class.APTS_UsageInputWS.loadUsageInputs: line 14, column 1

EQ AdminEQ Admin
Wrapper Class : 

global class APTS_UsageInputWrapper {

    public String EQ_WorkId { get; set; }
    public Integer EQ_Count { get; set; }
    public Boolean ValidateOnly { get; set; }
    public List<APTS_UsageInputWrapperData> data { get; set; }
Parmanand PathakParmanand Pathak

You can create below class  - 
public class JsonParser{
        public Boolean ValidateOnly{get;set;}
        public String EQ_WorkId{get;set;}
        public list<Data> Data{get;set;}
        public Integer EQ_Count{get;set;}
    public class Data{
        public Integer EQ_Quantity{get;set;}
        public String EQ_IssueNumber{get;set;}
        public String EQ_ServiceCode{get;set;}
        public String EQ_SourceSystem{get;set;}
        public String EQ_LoadMonth{get;set;}
        public String EQ_QuantityID{get;set;}
        public String EQ_RecordKey{get;set;}

And use below line in your class to parse your json - 
JsonParser obj = (JsonParser)JSON.deserialize(put your result variable here, JsonParser.class);

Let me know in case of any issue.

Parmanand Pathak.