[OpenLayers-Users] suggest adding try/catch around JSON.parse

Charlton Galvarino charlton at 2creek.com
Tue Dec 6 11:01:44 EST 2011


In OpenLayers/Format/JSON.js, it would be helpful to have another try/catch block.  Sometimes my incoming JSON is bad, and as the code stands now, it throws a .js error and fails.

Original:

    read: function(json, filter) {
        var object;
        if (this.nativeJSON) {
            object = JSON.parse(json, filter);
        } else try {
            /**
             * Parsing happens in three stages. In the first stage, we run the

Suggested change:

    read: function(json, filter) {
        var object;
        if (this.nativeJSON) {
            try {
               object = JSON.parse(json, filter);
            }
             catch(e) {
                 // Fall through if the parse fails.
             }
        } else try {
            /**
             * Parsing happens in three stages. In the first stage, we run the





Charlton Galvarino
1 (803) 233-6205 : voice
1 (803) 223-9579 :   fax
charlton at 2creek.com

P.O. Box 50960
Columbia, SC 29250



More information about the Users mailing list