Hi,
There is something simular in the Magritte Add-ons repository: the
Magritte-Json package. It's definitely usefull functionality!
Jan.
On Mon, Aug 8, 2011 at 8:15 PM, Nick Ager <nick.ager(a)gmail.com> wrote:
Hi,
I'm experimenting with a JSON converter for objects with Magritte
descriptions. So far I've added the following to GRObject:
jsonOn: aStream
| description |
description := self description.
description children isEmpty ifFalse: [
| first |
first := true.
aStream nextPut: ${.
description do: [ :each |
first
ifTrue: [ first := false ]
ifFalse: [ aStream nextPut: $, ].
aStream
json: each label;
nextPut: $:;
json: (each accessor read: self) ].
aStream nextPut: $} ]
you can then generate JSON from an object, for example:
((PRPage named: 'examplePage') contents: '!!Hello', String crlf,
'Hello
""world"" check') asJson
gives:
'{"Name":"examplePage","Visibility":false,"Navigation
Title":"ExamplePage","Tags":[],"Title":"ExamplePage","Owner":null,"Group":null,"Contents":{},"Plain
Text":"Hello\rHello world check","Environment":null,"Style
Sheet":null,"Shortcut Icon":null,"CSS Classes":null}'
The method fails with recursive structures, but otherwise is appears to
work well.
Does this look like a sensible approach? Has anyone else implemented
anything similar?
Thanks
Nick
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki