+ Start a Discussion
pranav shah 40pranav shah 40 

Json Parse Error for Web Services

Hi All,

I am getting following error for my class:
Unexpected parameter encountered during deserialization: name at [line:2, column:9]
errorCode: JSON_PARSER_ERROR

below is my code for same.
i am trying to insert account name thrugh workbench
@RestResource(urlMapping='/Account/*')
 global with sharing class NewCustCreation
 {
    //public String Status {get;set;}
    //public List<Account> Data {get;set;}
    //public String Message {get;set;}
    //public String ErrorCode {get; set;}
    
     public class Account
     {

        public String Name;
     }

    @HttpPost
    global static String dopost(String Name)
    {
        system.debug('-----------Name----------------------'+Name);
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response; 
         Account account =  new Account();
         account.name=name;
         String success = 'Welcome to Salesforce';
         String error = 'Error';
         if(Name!= '')
         {
              return Name;
         }
         else
         {
              return error;   
         }
         

    }
    public static NewCustCreation parse(String json)
        {
        return (NewCustCreation) System.JSON.deserialize(json, NewCustCreation.class);
        }
    }



Request Body:
{
"name":"Eniig Customer"
}
Best Answer chosen by pranav shah 40
SandhyaSandhya (Salesforce Developers) 
Hi,

Iam not sure if this the problem but your request body must be 
 
{
"Name":"Eniig Customer"
}

Capital N should be used.


Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya