Infinite recursion when POSTing Dictionary

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Infinite recursion when POSTing Dictionary

Sebastian Nozzi-2
> Sorry, I misread your answer.

No problem. What I wrote was wrong anyways. Turns out, for this case
I'd rather use the string version ;-)

(I then parse manually on the server... The problem is, that if I have
a structure like

{hello: 'amber',
 list: {a: 'b', c: 'd'}}

it gets converted to

{hello: 'amber',
 'list[a]': 'b',
'list[c]': 'd'}}


> I pushed another improvement. Now you can convert an Amber objec to a
> JSON object with: #asJSON or to a JSON string with: #asJSONString
Reply | Threaded
Open this post in threaded view
|

Re: Infinite recursion when POSTing Dictionary

Sebastian Nozzi-2
In reply to this post by Nicolas Petton

> Sorry, I misread your answer.

No problem. What I wrote was wrong anyways. Turns out, for this case
I'd rather use the string version... I then parse manually on the
server... ;-)

The problem is, that if I have a structure like:

{
 hello: 'amber',
 list: {a: 'b', c: 'd'}
}

when I was sending a JSON object and not a string, the keys got
converted to:
(this I see even on the browser with firebug)

{
 hello: 'amber',
 'list[a]': 'b',
 'list[c]': 'd',
}

This is apparently not a problem of Amber, so just ignore it. It's
either standard Javascript behaviour, or a JQuery issue. To work
around it I send the string-version and parse it on the server.

> I pushed another improvement. Now you can convert an Amber objec to a
> JSON object with: #asJSON or to a JSON string with: #asJSONString

Although I won't use it for now, the addition is very well
appreciated.

Thanks!

Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: Infinite recursion when POSTing Dictionary

Nicolas Petton
In reply to this post by Sebastian Nozzi-2
Where? On the server or client? what's the contents of the request?

From Amber I get this:

#{
        'hello' -> 'amber'.
        'list' ->  #{
                'a' -> 'b'.
                'c' -> 'd'
        }
} asJSONString

->  '{"hello":"amber","list":{"a":"b","c":"d"}}'

and then to get it back:

Smalltalk current readJSObject: (JSON parse:
'{"hello":"amber","list":{"a":"b","c":"d"}}')

->  a Dictionary('hello' -> 'amber' , 'list' -> a Dictionary('a' ->
'b' , 'c' -> 'd'))

Cheers,
Nico

On Wed, 2011-11-02 at 03:06 -0700, Sebastian Nozzi wrote:

> The problem is, that if I have
> a structure like
>
> {hello: 'amber',
>  list: {a: 'b', c: 'd'}}
>
> it gets converted to
>
> {hello: 'amber',
>  'list[a]': 'b',
> 'list[c]': 'd'}}
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Infinite recursion when POSTing Dictionary

Nicolas Petton
BTW, what about a convenience method to read a JSON string and answer a
Smalltalk object:

Smalltalk>>readJSONString: aString
        ^self readJSObject: (JSON parse: aString)

It would make it easier to load JSON strings.

Cheers,
Nico

On Wed, 2011-11-02 at 11:14 +0100, Nicolas Petton wrote:

> Where? On the server or client? what's the contents of the request?
>
> From Amber I get this:
>
> #{
> 'hello' -> 'amber'.
> 'list' ->  #{
> 'a' -> 'b'.
> 'c' -> 'd'
> }
> } asJSONString
>
> ->  '{"hello":"amber","list":{"a":"b","c":"d"}}'
>
> and then to get it back:
>
> Smalltalk current readJSObject: (JSON parse:
> '{"hello":"amber","list":{"a":"b","c":"d"}}')
>
> ->  a Dictionary('hello' -> 'amber' , 'list' -> a Dictionary('a' ->
> 'b' , 'c' -> 'd'))
>
> Cheers,
> Nico
>
> On Wed, 2011-11-02 at 03:06 -0700, Sebastian Nozzi wrote:
> > The problem is, that if I have
> > a structure like
> >
> > {hello: 'amber',
> >  list: {a: 'b', c: 'd'}}
> >
> > it gets converted to
> >
> > {hello: 'amber',
> >  'list[a]': 'b',
> > 'list[c]': 'd'}}
> >
> >
>


Reply | Threaded
Open this post in threaded view
|

Re: Infinite recursion when POSTing Dictionary

Amber Milan Eskridge
Hello

I would like to use that. :)
In some of my models, I already use something like this:

fromJSON: aJSONObject
| instance |
instance := self new.
^ instance
users: (aJSONObject users);
maps: (aJSONObject maps collect: [:each | Card fromJSON: each ]);
id: (aJSONObject id) asString;
yourself.

It would be interesting to have something along the lines of the NSCoding-protocoll so one could give different Coders to the objects and get different archives (JSON, YAML, XML, 280PLIST, …). That is used by Cocoa and Cappuccino to store the user interfaces as well as programm data. After unarchiving a message is send to all objects (#awakeAfterUsingCoder:, #awakeFromNib: and friends) so they can react to being unarchived.

See: <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i">http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i



On Wed, Nov 2, 2011 at 11:18 AM, Nicolas Petton <[hidden email]> wrote:
BTW, what about a convenience method to read a JSON string and answer a
Smalltalk object:

Smalltalk>>readJSONString: aString
       ^self readJSObject: (JSON parse: aString)

It would make it easier to load JSON strings.

Cheers,
Nico

On Wed, 2011-11-02 at 11:14 +0100, Nicolas Petton wrote:
> Where? On the server or client? what's the contents of the request?
>
> From Amber I get this:
>
> #{
>       'hello' -> 'amber'.
>       'list' ->  #{
>               'a' -> 'b'.
>               'c' -> 'd'
>       }
> } asJSONString
>
> ->  '{"hello":"amber","list":{"a":"b","c":"d"}}'
>
> and then to get it back:
>
> Smalltalk current readJSObject: (JSON parse:
> '{"hello":"amber","list":{"a":"b","c":"d"}}')
>
> ->  a Dictionary('hello' -> 'amber' , 'list' -> a Dictionary('a' ->
> 'b' , 'c' -> 'd'))
>
> Cheers,
> Nico
>
> On Wed, 2011-11-02 at 03:06 -0700, Sebastian Nozzi wrote:
> > The problem is, that if I have
> > a structure like
> >
> > {hello: 'amber',
> >  list: {a: 'b', c: 'd'}}
> >
> > it gets converted to
> >
> > {hello: 'amber',
> >  'list[a]': 'b',
> > 'list[c]': 'd'}}
> >
> >
>



12