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
rplrpl 

Please help me parse this json. I am getting an error: unexpected parameter Os

{"example":{"Os":"windows","Origin":"xyz"}} is my request string that is sent to a HTTPPost REST Web service in salesforce.

@RestResource(urlMapping='/NewIncident/*')
global without sharing class WSIncident {
    @HttpPost
    global static String createMobileCase(string example) {
        contact newCase = new contact();
        JSONParser jParser = JSON.createParser(example);


/*CAN SOME ONE PLEASE HELP ME PARSE THIS JSON*/

     return newCase.Id;
}
}
izay.ramos-irizarry1.3893936724146558E12izay.ramos-irizarry1.3893936724146558E12
The way I do it is creating a wrapper class that match the JSON string attributes and parse the string to the class using JSON.deserialize. Example:

public class testJSON{
          public String Os{get; set;}
          public String Origin{get; set;}
         
          public ConfirmationJSON(){
              this.Os = '';
              this.Origin = '';
          }
      }
     
      public class Mytest{
          public testJSON example{get; set;}
      }

Then deserialize it like this:

Mytest myTest = (Mytest)JSON.deserialize(example, Mytest.class);
                                  testJSON test = myTest.example;

Hope this helps