PDA

View Full Version : Ext.URLEncode Problem on JSON wth Array



flatburger
12 Oct 2007, 3:34 AM
i found this tutorial

Ext.urlEncode

i see this is a good approach, but i see if we implement in JSON whcih have array inside, this encode cannot be use.

any idea to send json with array notation inside

Frans

mystix
12 Oct 2007, 4:41 AM
i found this tutorial

Ext.urlEncode

i see this is a good approach, but i see if we implement in JSON whcih have array inside, this encode cannot be use.

any idea to send json with array notation inside

Frans

:-? hmmmm...



var myJsonObect = {
a: [1, 2, 3, 4, 5],
b: 3,
c: 'myStringValue'
};

Ext.urlEncode(myJsonObject); // returns "a=1&a=2&a=3&a=4&a=5&b=3&c=myStringValue"

BernardChhun
12 Oct 2007, 4:53 AM
maybe he was using a previous version of Ext?

jay@moduscreate.com
12 Oct 2007, 5:12 AM
i found this tutorial

Ext.urlEncode

i see this is a good approach, but i see if we implement in JSON whcih have array inside, this encode cannot be use.

any idea to send json with array notation inside

Frans
In the past, i've separated these array values and make them CSV - if the'yre numbers.

mystix
12 Oct 2007, 5:32 AM
maybe he was using a previous version of Ext?

:-/ both the 1.1.1 and 2.x urlEncode() methods do the same thing.

p.s. i checked all the way back to the yui-ext-0.33 release (which doesn't contain the urlEncode() method). the 1.0 urlEncode() method works the same (internal code's slightly different though).

BernardChhun
12 Oct 2007, 7:12 AM
I just tried out some variations of what people usually thinks is an array and here's one occasion where it isn't encoded properly:


var myJsonObject = {
a: {"1" : 1, "2": 2, "3" : 3},
b: 3,
c: 'myStringValue'
};

Ext.urlEncode(myJsonObject); // "b=3&c=myStringValue"

solution:
I encode dictionnaries in parameters using the JSON utils :)

mystix
12 Oct 2007, 8:40 AM
I just tried out some variations of what people usually thinks is an array and here's one occasion where it isn't encoded properly:


var myJsonObject = {
a: {"1" : 1, "2": 2, "3" : 3},
b: 3,
c: 'myStringValue'
};

Ext.urlEncode(myJsonObject); // "b=3&c=myStringValue"

solution:
I encode dictionnaries in parameters using the JSON utils :)

eh?


a: {"1" : 1, "2": 2, "3" : 3}

isn't an array by any means in js. it's a js object.

that said, your test does show one limitation -- not of the urlEncode() method, but of passing arguments to the server via a URL string -- and brings up one question -- how, if it be possible, should one represent an object value in a URL string? :-? (notice that the urlEncode() method ignores function values also)

[edit]
d'oh... didn't catch that last bit of your post... "I encode dictionnaries in parameters using the JSON utils". :">

flatburger
12 Oct 2007, 9:22 AM
thx for the fast reply, i will check in my backend.