PDA

View Full Version : [CLOSED] Ext.decode Error!



AndreaCammarata
17 Jun 2010, 3:54 PM
Hi All,
I'm having a trouble calling a simple Ext.decode of a simple json string like the following one:



{success: true, message: 'hello'}

the error is the following



SyntaxError: Unable 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

Jamie Avins
17 Jun 2010, 4:05 PM
Is there any more context you can provide on the problem? Is that the exact string you are trying to decode?

evant
17 Jun 2010, 4:14 PM
Just a guess, but if it's using native decoding, it might require the labels to be quoted as well.

AndreaCammarata
17 Jun 2010, 4:21 PM
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:



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')
}
}
})
}
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.

Jamie Avins
17 Jun 2010, 4:32 PM
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.

AndreaCammarata
17 Jun 2010, 10:42 PM
Hi,
Yes, I already tried to edit my server script by returning me the data



{'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.

AndreaCammarata
18 Jun 2010, 11:13 AM
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

TommyMaintz
18 Jun 2010, 11:19 AM
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.

AndreaCammarata
18 Jun 2010, 11:26 AM
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.

aw1zard2
18 Jun 2010, 11:49 AM
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.



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