1
votes

When I'm sending a HTTP Post request from my Apex class and trying to parse the response using JSON Parser, then I'm getting this error. Following is the code that gives me "Method does not exist or incorrect signature: [String].createParser(String)"

   req.setMethod('POST');
   res = http.send(req);
   JSONParser parser = JSON.createParser(res.getBody());

As far as I know createParser is a static method and we can call it like this. I did refer the salesforce.com's document at - http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsonparser.htm

Could you please help me aout here and correct me where I'm going wrong? Thanks

1
Have by any chance declared a variable named JSON of type String somewhere preceding this code?JCD

1 Answers

3
votes

Are you using a variable named JSON? Remember, Apex can be case insensitive. I had a similar issue (though parsing a string, not an http response) maybe yours is the same:

public static someMethod Parser(String json) {
    ...    
    JSONParser parser = JSON.createParser(json);
    ...

Note that the parameter I passed. This particular circumstance can be solved by renaming the 'json' parameter to something else.

public static someMethod Parser(String jStr) {
    ...    
    JSONParser parser = JSON.createParser(jStr);
    ...

and voila!