how to write custom json reader

  • Hello,

    I am using extJS 2.1 in combo with ColdFusion MX7. I have a grid setup using the Ext.data.JsonStore as my data store, and it works fine on my local machine. I am running into a problem, however, when I move the code to my company's development server. The dev server is running a special version of ColdFusion MX7 which inserts the following line at the beginning of every html response:

    This breaks the JsonStore's default reader. How would I go about setting up a custom reader which can use a regex to strip this line out of the html response?Thanks!Mike


  • I found a way to solve my problem: I overrode the Ext.data.JsonReader function:

    Ext.override(Ext.data.JsonReader, {
    read : function(response){
    var json = response.responseText;
    json = json.replace(/]*>/, "");
    var o = eval("("+json+")");
    if(!o) {
    throw {message: "CFJsonReader.read: Json object not found"};
    }
    if(o.metaData){
    delete this.ef;
    this.meta = o.metaData;
    this.recordType = Ext.data.Record.create(o.metaData.fields);
    this.onMetaChange(this.meta, this.recordType, o);
    }
    return this.readRecords(o);
    }
    });You can see that line four does a regex replacement to the json string in order to strip out the meta tag. Is there a cleaner way to do this?

    Thanks,
    Mike


  • search on this, I recall some threads about something possibly similar. Something about special coldfusion handling.


  • Hello,

    I have a similar issue. My json data is very complex, arrays embedded in arrays. I don't think you can use the JsonStores to get the 2nd and third level array elements. How do I get an event call for the read of the jsondata before it goes into the store. I can't override the JsonStore since I have 5 or six different ones.

    Rinaldo

    I see a similar questions was asked a year ago.

    http://www.extjs.com/forum/showthread.php?t=37367&highlight=subclass


  • I tried searching briefly and couldn't find what I was thinking of, only found:
    http://extjs.com/forum/showthread.php?t=8230&highlight=coldfusion

    aconran is one of the community Coldfusion guys though.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about how to write custom json reader , Please add it free.