PDA

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



murrah
29 Mar 2013, 2:42 PM
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

mitchellsimoens
31 Mar 2013, 6:08 AM
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


var str = '{a:2}',
obj = Ext.decode(str);

console.log(obj);

murrah
31 Mar 2013, 12:47 PM
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

mitchellsimoens
1 Apr 2013, 5:24 AM
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?

murrah
1 Apr 2013, 11:42 AM
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:

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);

}
});

<!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>

42820

Thanks again.
Murray