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
Gopi chand 11Gopi chand 11 

System.JSONException: Unexpected character (',' (code 44)): was expecting a colon to separate field name and value at [line:1, column:15]

System.JSONException: Unexpected character (',' (code 44)): was expecting a colon to separate field name and value at [line:1, column:15]
I am having an issue in a test class where I am generating a mock JSON string.
 I am getting an exception error on the string,
 but I am not sure what is wrong with the string format. In the debug log I received the following error message:
System.JSONException: Unexpected character (',' (code 44)): was expecting a colon to separate field name and value at [line:1, column:15]
I have included the JSON string below:

My Class code:

HttpRequest accessTokenReq = new HttpRequest();
        HttpResponse accessTokenRes = new HttpResponse();
        Http accessTokenHttp= new Http();
        accessTokenReq.setMethod('POST');
        accessTokenReq.setEndpoint('My Url');
        accessTokenRes = accessTokenHttp.send(accessTokenReq);
        Map<String,Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(accessTokenRes.getBody());
        String access_token = (String)responseMap.get('access_token');
        System.debug(access_token);
My test class code :

isTest
global class MockHttpResponseGenerator implements HttpCalloutMock {
   
    global HTTPResponse respond(HTTPRequest req) {
        
    
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'text\\csv');
        res.setBody('{"EVENT_TYPE","TIMESTAMP","REQUEST_ID","ORGANIZATION_ID","SESSION_ID","USER_ID","USER_TYPE","CONTEXT","ENTITY","LANGUAGE","LAST_VERSION","ARTICLE_STATUS","ARTICLE_ID","ARTICLE_VERSION_ID","USERNAME","ARTICLE_VERSION","TIMESTAMP_DERIVED"\n"KnowledgeArticleView","20171106090422.918","4EGnl6nFNZWltlF1v7x_4-","00D1g0000008bXG","5Frlit+6RHn683d4AUh2Y87rsBNcNKZpCju+0yUIo5Y=","00536000006CZAI","A","apex","Knowledge__kav","en_US","1","o","kA01g000000CahZ","ka01g000000CanM","","2","2017-11-06T09:04:22.918Z"\n"KnowledgeArticleView","20171106090510.556","4EGnntNC_IDBUGF1v7liV-","00D1g0000008bXG","5Frlit+6RHn683d4AUh2Y87rsBNcNKZpCju+0yUIo5Y=","00536000006CZAI","A","apex","Knowledge__kav","en_US","1","o","kA01g000000Cahe","ka01g000000CanR","","1","2017-11-06T09:05:10.556Z"}');
        
        res.setStatusCode(200);
        return res;
    }
}

Does anyone have any idea what could be incorrect with this string format in relation to the error message?

Thanks so much!
v varaprasadv varaprasad
Hi Gopi,

Create a static resource with sample response body and call it in the test class.

More Info : 

http://salesforceprasad.blogspot.sg/2017/05/test-class-for-xml-dom-parser-and.html

Hope this helps you.

Thanks
Varaprasad