(see http://www.json.org )
--
Jeremy C B Nicoll - my opinions are my own.
Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "nnn" by "284".
This might help. It uses arrays and directories (stems are out).
Because I call the makearray method if you do not pass an array or
directory, you could use it for other objects as well (lists, queue,
etc). Created it to work with ooRexx 3.1. The sample below shows how
you might want to serialize a rexx object in JSON. The only other
method you should really care about is the "fromJSON" method. It
requires a string of json text. It returns a rexx object. I think it's
pretty straight forward. Please let me know if you have problems. It
does not handle unicode. I have been using this instead of XML for a
lot of our AJAX websites. Thanks!
--
Brandon Cherry
/* serialize.rex */
test = .array~new()
test~append(.directory~new())
test[test~last]['name'] = 'Adam'
test[test~last]['location'] = 'NC'
test[test~last]['terminated'] = .true
test[test~last]['number'] = 2
test[test~last]['description'] = 'The quick brown fox jumped over the
lazy dog.'.endofline||,
'The quick brown fox jumped over the
lazy dog.'
test~append(.directory~new())
test[test~last]['name'] = 'Bob'
test[test~last]['location'] = 'SC'
test[test~last]['terminated'] = .false
test[test~last]['number'] = 10
test[test~last]['description'] = .nil
test~append(.directory~new())
test[test~last]['name'] = 'Carl'
test[test~last]['location'] = 'VA'
test[test~last]['terminated'] = .false
test[test~last]['number'] = 15
test[test~last]['description'] = .nil
say .json~new()~toJSON(test)
::requires 'json.cls'
> This might help...
Thank-you. I've done a little experimenting and it looks useful so far. My
only real problem is not well understanding the oo aspects of the code too
well. I may be back with questions in due course.
I found a useful utility on the net which 'pretty-prints' a JSON structure,
eg reading it from a file. The output can be redirected into a second file,
making it a quick and easy way to get a look at a structure's contents.
The pretty-printing, if one does it in a Windows console / command window,
is displayed with colouring of the contents, somewhat like a text editor's
syntax colouring, which looks very nice! The utility (and a picture of
coloured output) is at:
http://www.raboof.com/Projects/TidyJson/
--
Jeremy C B Nicoll - my opinions are my own.
Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "nnn" by "284".