1. #1
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    384
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default Ext.decode() - properties must be quoted which is different to EXTJS version

    Ext.decode() - properties must be quoted which is different to EXTJS version


    Hi,

    It seems that the Ext.decode() function behaves differently from the ExtJS version. With Touch, if you dont quote the properties it throws a sytax error.

    ExtJS:
    str = '{"a":2}'; and str = '{a:2}'; both work - with or without quotes

    Touch:
    str = '{"a":2}'; works
    str = '{a:2}'; DOES NOT work - throws a JSON syntax error

    FYI

    Murray

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    What version are you using? I've tried 2.0.1.1, 2.0.2, 2.1.0, 2.1.1 and 2.2.0 RC1 and it works as expected

    Code:
    var str = '{a:2}',
        obj = Ext.decode(str);
    
    console.log(obj);
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    384
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default


    Hi Mitch.

    Just retested to confirm the problem.

    Using Touch version 2.1.0 throws "Uncaught SyntaxError: Unexpected token a" using Chrome v26.

    I first encountered the problem using Architect (latest version) which is using the Library http://cdn.sencha.com/touch/sencha-touch-2.1.1/

    Thanks,
    Murray

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Just tried it again with Chrome and Safari with 2.1.0 and 2.1.1 and I get an object returned with a : 2 (using my code). Is this on a device?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    384
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default


    Thanks Mitch. It is on a PC: Win7 64bit, Chrome Version 26.0.1410.43 m. I also tried Safari 5.1.7 and it throws: SyntaxError: JSON Parse error: Expected '}' using the same test code. ie works fine with {"a":2} but not {a:2}

    I originally encountered the problem when using Architect 2 (Library http://cdn.sencha.com/touch/sencha-touch-2.1.1/). I have a store with a model using a rest proxy. When I loaded the store in Architect, if I set my server to return unquoted json (my default setting) it threw an error. When I set the option for quoted json, it worked fine. So, to test, I created the sample code directly in my local copy of Sencha Touch with the results I am seeing.

    Very strange that you are not getting the same results. I cant think what else to try or tell you. If I am the only one with the error it must be me but I cant see what could be wrong. This is out of my expertise but could it be some kind of char encoding problem?

    Here is my code:
    PHP Code:
    Ext.application({
        
    name'Sencha',

        
    launch: function() {
             
    // This works:
            
    var str '{"a":1}';
            var 
    obj Ext.decode(str);
            
    console.log(obj);
               
               
    // This throws the syntax error
            
    var str2 '{a:1}';
            var 
    obj2 Ext.decode(str2);
            
    console.log(obj2);
               
        }
    }); 
    PHP Code:
    <!DOCTYPE html>
    <
    html>
    <
    head>
        <
    title>Getting Started</title>
        <
    link rel="stylesheet" href="../sencha-touch/resources/css/sencha-touch.css" type="text/css">
        <
    script type="text/javascript" src="../sencha-touch/sencha-touch-all-debug.js"></script>
        <script type="text/javascript" src="apptest.js"></script>
    </head>
    <body></body>
    </html> 
    JSONError.jpg

    Thanks again.
    Murray
    Last edited by murrah; 1 Apr 2013 at 4:42 PM. Reason: Add image

Thread Participants: 1