Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default [CLOSED] Ext.decode Error!

    [CLOSED] Ext.decode Error!


    Hi All,
    I'm having a trouble calling a simple Ext.decode of a simple json string like the following one:

    PHP Code:
    {successtruemessage'hello'

    the error is the following

    PHP Code:
    SyntaxErrorUnable to parse JSON string
    sencha
    -touch-beta-0.90:5489 
    Calling the same on Ext 3.21 framework, everything works fine!
    Does someone notice the same error?

    Thanks
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Is there any more context you can provide on the problem? Is that the exact string you are trying to decode?

  3. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,049
    Vote Rating
    657
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Just a guess, but if it's using native decoding, it might require the labels to be quoted as well.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  4. #4
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Yes, that is the exact string I'm trying to encode.
    The error raise when i try to encode the response.responseText got back from an Ext.Ajax.request success event, like the following one:

    PHP Code:
    var doLogin = function() {
        
    Ext.Ajax.request({
             
    urlmyUrl,
             
    method'post',
             
    params: {
                
    username'xxx',
                
    password'yyy'
             
    },
             
    success: function(responseopts) {
                
                var 
    result Ext.encode(response.responseText);
                
                switch(
    result.message){
                    case 
    'OK':
                        
    alert('OK');
                        break;
                    default:
                        
    alert(response.responseText);
                        
    alert('KO')
                }
            }
        })

    The code crash at the line var result = ..., but if I replace that line with a simple alert(response.responseText), I can see clear the same string I previously post.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  5. #5
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Have you tried quoting your properties? We try to use native methods in the modern browsers the mobile devices provide. They can unfortunately have some stricter syntax. We had a similar issue with QSA in DomHelper since we no longer fall back to javascript in Touch.

  6. #6
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Hi,
    Yes, I already tried to edit my server script by returning me the data

    PHP Code:
    {'success'true'message''hello'
    but I got the same error, nothing change.
    I tested the script with Safari 5 and Safari Mobile on my iPad, I don't know if this can help.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  7. #7
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Does anyone got the same errror?
    Jamie did you tried to reproduce this error with a simple script?

    I'm literally blocked, I'm not able to going on developing the application beacause i can't get the data inside the response message.
    Any idea?

    Thanks
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  8. #8
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    So after some attempts of trying to get this to work in the Safari Debugger we found out that valid JSON according to the native JSON implementation uses double quotes inside the JSON data rather then single ones.
    If you change your response to: {"success": true, "message": "hello"} it seems to be able to parse it.

  9. #9
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Posts
    1,395
    Vote Rating
    23
    AndreaCammarata has a spectacular aura about AndreaCammarata has a spectacular aura about

      0  

    Default


    Thank you Tommy!
    I tested it like you suggest and it perfectly works now.

    I tested my script in FireFox and Chrome too, but it doesn't worked.
    Now everything is ok with every browser.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


  10. #10
    Sencha User aw1zard2's Avatar
    Join Date
    Sep 2009
    Location
    Dallas, Texas
    Posts
    577
    Vote Rating
    32
    aw1zard2 has a spectacular aura about aw1zard2 has a spectacular aura about

      0  

    Default


    Just a rule of thumb from php I've always used this code snippet. Much easier keeping track of array sets in php then using the default json function json_encode.

    PHP Code:
    $rtnjson["success"] = true;
    $rtnjson["message"] = "Login successful!";
    echo 
    json_encode($rtnjson); 

Similar Threads

  1. Replies: 4
    Last Post: 14 Jun 2009, 10:52 PM
  2. scope used for Ext.decode (Ext.util.JSON.decode)
    By conorarmstrong in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 1 Jun 2009, 12:29 PM
  3. Replies: 1
    Last Post: 12 Mar 2008, 12:53 PM
  4. [2.0.2][CLOSED] Ext.util.JSON : this.decode
    By Qedinux in forum Ext 2.x: Bugs
    Replies: 2
    Last Post: 2 Mar 2008, 7:55 PM

Thread Participants: 4