+ Start a Discussion
SBKSBK 

JSONParser class & script execution limitation.

I am developing a Site and I do a callout to get some information.

 

I use the Apex JSONParser from : http://code.google.com/p/apex-library/source/browse/trunk/JSONObject/src/unpackaged/classes/JSONObject.cls

to parse the HttpResponse. I downloaded the code installed it my environment

and using it.  However I run into  System.Exception: Too many script statements: 200001.

 

Is there any other JSONParser which does a better job in parsing, so I do not hit the limitation?

 

I do not understand why the JSONParser is not part of the Apex System package so

it does not compete with the user limitations.

 

Thanks, 

 

jeffdonthemic2jeffdonthemic2

Ron Hess and I did some work on the JSON parser in January so it is pretty much up to date. AFAIK, it's the only parser available for Salesforce.

 

Here is some more info. Not sure if it helps or not. 

 

Jeff Douglas
Appirio, Inc.
http://blog.jeffdouglas.com

Kenji775Kenji775

Not sure if it will help you any, but I wrote a simple apex class that takes a query, and returns the results in JSON. Maybe it will help you.

 

 

public class queryToJSON { String jsonReturn; /** invoked on an Ajax request */ public void getJson() { //There should be a parameter called QueryString in the URL. Map<string,string> params = ApexPages.currentPage().getParameters(); jsonReturn = '{ "queryString": "'+params.get('queryString')+'", '; if(params.get('queryString').length() > 1) { try { //Dynamic SOQL Query based off URL queryString param. use String.escapeSingleQuotes to help //prevent SOQL injection. List<sObject> records = Database.query('select ' +params.get('queryString')); if (!records.isEmpty()) { //This is a mapping of the column names returned by the query Map<String, Schema.SObjectField> columns = records.getSObjectType().getDescribe().fields.getMap(); jsonReturn = jsonReturn + ' "resultSet": ['; for (sObject c : records) { //Now for every column in the query, I need to construct a new JSON "element" //I can do that statically by typing something like this //cjson.putOpt('"id"', new JSONObject.value(c.Id)); jsonReturn = jsonReturn + '{'; for(String columnName : columns.keySet()) { try { //Try to get the value of the column name. If it isn't there, then it tosses //an error, no big deal. string cellVal = String.valueOf( c.get(columnName)); jsonReturn = jsonReturn + '"'+columnName+'": "'+cellVal+'",'; } catch(System.Exception ex) { //jsonReturn = jsonReturn + '"'+columnName+'": "'+ex.getMessage()+'",'; } } jsonReturn = jsonReturn.substring(0, jsonReturn.length() - 1); jsonReturn = jsonReturn + '},'; } jsonReturn = jsonReturn.substring(0, jsonReturn.length() - 1); } } catch(Exception ex) { jsonReturn = jsonReturn + '"ERROR": "'+ex.getMessage()+'"'; } } jsonReturn = jsonReturn + ']}'; } // Returns the JSON result string public String getResult() { return jsonReturn; } }