-
17 Jun 2010 3:54 PM #1
[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:{success: true, message: 'hello'}
the error is the following
Calling the same on Ext 3.21 framework, everything works fine!PHP Code:SyntaxError: Unable to parse JSON string
sencha-touch-beta-0.90:5489
Does someone notice the same error?
ThanksSencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
17 Jun 2010 4:05 PM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,651
- Vote Rating
- 14
Is there any more context you can provide on the problem? Is that the exact string you are trying to decode?
-
17 Jun 2010 4:14 PM #3
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!
-
17 Jun 2010 4:21 PM #4
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:
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.PHP Code:var doLogin = function() {
Ext.Ajax.request({
url: myUrl,
method: 'post',
params: {
username: 'xxx',
password: 'yyy'
},
success: function(response, opts) {
var result = Ext.encode(response.responseText);
switch(result.message){
case 'OK':
alert('OK');
break;
default:
alert(response.responseText);
alert('KO')
}
}
})
}
Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
17 Jun 2010 4:32 PM #5Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,651
- Vote Rating
- 14
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.
-
17 Jun 2010 10:42 PM #6
Hi,
Yes, I already tried to edit my server script by returning me the data
but I got the same error, nothing change.PHP Code:{'success': true, 'message': 'hello'}
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
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
18 Jun 2010 11:13 AM #7
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?
ThanksSencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
18 Jun 2010 11:19 AM #8Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
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.
-
18 Jun 2010 11:26 AM #9
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
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
18 Jun 2010 11:49 AM #10
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);
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
[CLOSED][3.0rc2] json decode throws error without a meta tag
By dolittle in forum Ext 3.x: BugsReplies: 4Last Post: 14 Jun 2009, 10:52 PM -
scope used for Ext.decode (Ext.util.JSON.decode)
By conorarmstrong in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 1 Jun 2009, 12:29 PM -
[2.0.2][CLOSED] API Doc Class Ext encode/decode documenation mistake
By dyndan in forum Ext 2.x: BugsReplies: 1Last Post: 12 Mar 2008, 12:53 PM -
[2.0.2][CLOSED] Ext.util.JSON : this.decode
By Qedinux in forum Ext 2.x: BugsReplies: 2Last Post: 2 Mar 2008, 7:55 PM


Reply With Quote

