Dictionary Inspector / JSON Encoding

December 27, 2010

Dictionary Inspector

Dictionary Inspector


http://www.silversmalltalk.com

The dictionary inspector is now functional enough to add, remove and inspect dictionary entries. Code used in the example above is here:
X := Dictionary new.
X at: 'ying' put: 'yang'.
X at: 'one' put: 111.
X at: 'two' put: 2.222.
X at: 'nothing' put: nil.
X at: 'yes' put: true.
X at: 'no' put: false.
X at: 'list' put: #('this' 'is' 'a' #(1 2 3 4) 'list') asList.
X inspect

There are two new JSON methods available:
— “encode” converts a Smalltalk object to JSON format
— “decode” converts a JSON string to a Smalltalk object

Note that for the moment, only the following can be converted to/from JSON:

  • nil
  • true
  • false
  • Integer
  • Double
  • String
  • List
  • Dictionary

Arrays are coerced to Lists before conversion.

Using the example dictionary above:
“X encode” will produce a JSON string of the dictionary.
“X encode decode” will give the original dictionary

In the coming weeks I will be adding JSON conversions to more classes of objects.

However, the functionality that is now in place is sufficient for most basic client-server communications.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: