PDA

View Full Version : Json Message malformed



klaodeli
7 Sep 2010, 2:44 PM
When I send a Json message from Client to Server, with this code:


recordsToSend = Ext.encode(recordsToSend);
Ext.MessageBox.alert("Mex Json",recordsToSend); //here I see message json format that will be send
Ext.Ajax.request({
url : 'CreateServlet', //'successTrue.js'
params : {
records : recordsToSend
},

....
....

From Client side the message is in json format:

records [{"id":"21","firstname":"Ale","lastname":"Scud","zipcode":"1111","newRecordId":""}]

In server-side I receive a message in this format:

records=%5B%7B%22id%22%3A%2221%22%2C%22firstname%22%3A%Ale%22%2C%22lastname%22%3A%22Scud%22%2C%22zipcode%22%3A%221111%22%2C%22newRecordId%22%3A%22%22%7D%5D

Why??? :((

Do I need a json decoder?? How can I retrieve a json object on the server-side? (I use java servlet, for decode json object i used THIS code (http://read.pudn.com/downloads122/sourcecode/web/518235/foundations-of-ajax-examples/Chapter03/src/java/ajaxbook/chap3/JSONExample.java__.htm) )

Condor
8 Sep 2010, 12:14 AM
You want:

Ext.Ajax.request({
url: 'CreateServlet', //'successTrue.js'
jsonData: {
records: recordsToSend
}
});
(the default is form encoding and not json encoding)

klaodeli
8 Sep 2010, 8:16 AM
You want:

Ext.Ajax.request({
url: 'CreateServlet', //'successTrue.js'
jsonData: {
records: recordsToSend
}
});
(the default is form encoding and not json encoding)

thanks!!! it works!