+ Start a Discussion
pranav shah 40pranav shah 40 

String To Json Conversion

How can i convert the below string in the  web service class in JSON..

please help..

@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;   
         }
         

    }
Akshay_DhimanAkshay_Dhiman
Hi Pranav Shah 40

string to JSON conversion.

use this JSON class Method:

public static System.JSONParser createParser(String jsonString).

More about details please visit this link:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm

Please mark as best answer if it helps you.

Thanks 
Akshay​