Results 1 to 2 of 2

Thread: [RESOLVED] Ext.JSON.decode() error - Extjs 6.6

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Dec 2008
    Location
    France
    Posts
    319
    Vote Rating
    2
      0  

    Default [RESOLVED] Ext.JSON.decode() error - Extjs 6.6

    I'm facing a strange behaviour.

    I've this message in Firefox console :
    Code:
    Ext.JSON.decode(): You're trying to decode an invalid JSON String
    When i trace the error, i come in the line 56166 of ext-all-rtl-debug.js :
    Code:
        me.decode = function(json, safe) {
            try {
                // check USE_NATIVE_JSON here so it can be changed if needed
                if (hasNative && Ext.USE_NATIVE_JSON) {
                    return JSON.parse(json);      <== error appears here
                }
                return doDecode(json);
            } catch (e) {
                if (safe) {
                    return null;
                }
                Ext.raise({
                    sourceClass: "Ext.JSON",
                    sourceMethod: "decode",
                    msg: "You're trying to decode an invalid JSON String: " + json
                });
            }
        };
    I put a breakpoint to check what happens.
    The "json" parameter is as simple as :
    Code:
    {"success":false,"message":"blabla","data":[],"total":0,"deconnexion":0}
    On the breakpoint, i check :
    Code:
    JSON.parse(json)
    It says :
    Code:
    SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
    The json string is validated by JsonLint and Mozilla MDN

    Any idea of what happens ?
    Last edited by senacle; 11 Oct 2018 at 3:15 AM. Reason: Solution found

  2. #2
    Sencha User
    Join Date
    Dec 2008
    Location
    France
    Posts
    319
    Vote Rating
    2
      0  

    Default

    Ok, i've found what is wrong.

    I'm using a store with a rest proxy with reader and writer of type json.
    In Extjs 6.5, onRestException of the proxy, i take :
    Code:
    var reponse = Ext.JSON.decode(response.responseText);
    In Extjs 6.6, it seems there is some change.
    Code:
    var reponse = Ext.JSON.decode(response.responseText);
    is not working but
    Code:
    var reponse = Ext.JSON.decode(response.responseJson);
    seems OK.

    In fact,
    Code:
    response.responseJson
    is already well json formated.
    So no need to use Ext.JSON.decode again.

    Thus, the good way in Exyjs 6.6 is :
    Code:
    var reponse = response.responseJson;

    After checking the doc, i saw : the responseType is a new property of Ext.data.reader.Json in Extjs 6.6.
    Don't forget it if you need to upgrade your app to the version 6.6

Similar Threads

  1. [FIXED] JSON.decode error when JSON includes Line Separator character.
    By thomas.hardwick in forum Ext 5: Bugs
    Replies: 2
    Last Post: 18 Apr 2016, 11:54 PM
  2. Replies: 2
    Last Post: 27 Aug 2013, 2:23 AM
  3. IE json decode syntax error
    By JimB in forum Ext 3.x: Help & Discussion
    Replies: 7
    Last Post: 4 Aug 2011, 6:47 AM
  4. Error with decode and JSON
    By mcbaker in forum Sencha Touch 1.x: Discussion
    Replies: 4
    Last Post: 21 Dec 2010, 6:36 AM
  5. JSON decode without JS Error on faulty JSON possible?
    By Wolfgang in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 23 Jul 2007, 11:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •