New parse and stringify for cJobject

67 views
Skip to first unread message

bruce

unread,
Mar 25, 2013, 1:32:27 AM3/25/13
to excel-r...@googlegroups.com

If you have been using cJobject for working with json and VBA you’ll be used to this...

to create jSon from a cJobject

s = j.serialize

and the very laborious to create an object from jSon

set j = new cjobject

set j = j.init ( Nothing).deSerialize(s) 

This also had the annoying side effect of creating an additional object level for j  as below.

{"_deserialization":{"key":100,"details":{"name":"fred","age":20},"list":["engineer","mathematician","cook" ]}}

javaScript implementations have now pretty much settled on JSON.parse for deSerialize and JSON.stringify () for serialize, so I’ve added a couple of things to cJobject to bring it into line.

To make json in VBA you can now use either

s=j.stringify()

or

JSONStringify(j)

 

and to make a cJobect from jSon

set j = JSONParse (s)

 

Not only does this bring cJobject it more into line with javaScript , it also gets rid of the additional object level introduced by j.deserialize()

The old methods will continue to work as before, so there is no need to change any existing code.


Bruce

Reply all
Reply to author
Forward
0 new messages