+ Start a Discussion
sailersailer 

How to do the JSON PARSER Dynamically at run time

Hello Everyone,

When i hard code the values in JSON it works ,Now i need to get the JSON structure when the records is inserted ,the values are comming in apex call out call ,not assiging  to teh JSON
public class JSONParserUtil {

    @future(callout=true)
   
    public static void parseJSONResponse(String Acctname,String ids)
   // public static void parseJSONResponse()
     {      
        String AcctNameJson;
        system.debug('AccountName______________________________'+AcctName);
         system.debug('AccountName______________________________'+ids);
         String JSONContent = '{folionum: AcctName, acctids: ids}'; the values are not assiging here
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'http://sherlockhomes.cloudapp.net/api/values';
        request.setEndPoint(endpoint);
        request.setHeader('content-type', 'application/json; charset=utf-8');

        request.setMethod('POST');
        //String strbody = '{folionum:AcctNameJson}';
       // var obj = {};
       
       // String JSONContent = '{"folionum":Acctname,"acctids":ids}';
        system.debug('strbody ____________'+JSONContent);
        // String strbody = '{"folionum":48430721840}';
        request.setBody(JSONContent );
       // request.setBody(strbody);
        HttpResponse response = httpProtocol.send(request);
        String jsonInput = response.getBody();
        system.debug('===>'+jsonInput);
        System.debug('Respone_____________________'+response.getBody());
     }
}

But when i look at the Debug Log

9:54:30.042 (42485000)|SYSTEM_METHOD_ENTRY|[9]|System.debug(ANY)
09:54:30.042 (42513000)|USER_DEBUG|[9]|DEBUG|AccountName______________________________48430721840
09:54:30.042 (42521000)|SYSTEM_METHOD_EXIT|[9]|System.debug(ANY)
09:54:30.042 (42532000)|SYSTEM_METHOD_ENTRY|[10]|System.debug(ANY)
09:54:30.042 (42541000)|USER_DEBUG|[10]|DEBUG|AccountName______________________________001S000000fVl8DIAS
09:54:30.042 (42546000)|SYSTEM_METHOD_EXIT|[10]|System.debug(ANY)
strbody ____________{folionum: AcctName, acctids: ids}
The values are not populating here


Can anyone please help out
Best Answer chosen by sailer
Satish_SFDCSatish_SFDC
You will have to append the values. 

String JSONContent = '{folionum: '+ AcctName + ', acctids:'+ ids+'}';

Regards,
Satish Kumar

All Answers

Satish_SFDCSatish_SFDC
You will have to append the values. 

String JSONContent = '{folionum: '+ AcctName + ', acctids:'+ ids+'}';

Regards,
Satish Kumar
This was selected as the best answer
sailersailer
Thanks Satish