You need to sign in to do that
Don't have an account?
sidb
JSONParser Error
Hi
I am writing a JSON Parser Apex class and following the documentation. I get the following error:
Error: YelpAPIController Compile Error: Illegal assignment from JSONParser to JSONParser at line 56 column 10
Here is my code:
public class JSONParserUtil {
@future(callout=true)
public static void parseJSONResponse() {
Http httpProtocol = new Http();
// Create HTTP request to send.
HttpRequest request = new HttpRequest();
// Set the endpoint URL.
String endpoint = 'http://www.cheenath.com/tutorial/sfdc/sample1/response.php';
request.setEndPoint(endpoint);
// Set the HTTP verb to GET.
request.setMethod('GET');
// Send the HTTP request and get the response.
// The response is in JSON format.
HttpResponse response = httpProtocol.send(request);
System.debug(response.getBody());
// Parse JSON response to get all the totalPrice field values.
JSONParser parser = JSON.createParser(response.getBody());
Double grandTotal = 0.0;
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
(parser.getText() == 'totalPrice')) {
// Get the value.
parser.nextToken();
// Compute the grand total price for all invoices.
grandTotal += parser.getDoubleValue();
}
}
system.debug('Grand total=' + grandTotal);
}
}
I am not sure what wrong here. The error is not explaining anything.
Thanks
Sid
Errors like this are normally beause you have a class with the same name, do you have a class called JSONParser ?
I also had the following exceptions
So to resolve that issue I added System. to every sub class constructor which was missing after JSON2Apex conversion, ie:
Before After: Hope that helps.
try replacing With
Your code (just to make it readable)