« List dialog with chec… | Home | Six months until MBS … »

Moving to new JSONMBS class

If you used our older JSONMBS class and now move to 23.5 version of MBS Xojo Plugins, you may notice a few changes. The new class is better in many ways, like interface compatible to JSONItem class, adds new Query, Search and Replace methods as well as handling errors better.

We got new kType* constants for new node types. Error, True, False and Number types are gone and we got new things like Boolean, ByteString, Int64, Single, Double and UInt64. The byte string is for handling MemoryBlocks in JSON, which can encoded as Hex, Base64 or Base64URL as needed.

We now raise exceptions for all bad operations. So checking handle for 0 and checking ParseError property is gone. You can inspect the exception for it's message property to see an error message.

We preserve numbers in exact representation. If you store 1.2345 as currency into JSON with our plugin, it will stay 1.2345 and not convert internally to a double and get output as 1.2344999999999999307. Our IsNumber function handles this correctly. So if a floating point number is stored internally as string, you may see kTypeString for it, but IsNumber returns true as it's a string we use to hold a number and output it as number. We also got functions like IsInt64, IsUInt64, IsInt32 and IsUInt32 which check for IsNumber and the range.

Some methods are gone for now like Text, SuffixObject and EqualContents. Not sure if someone needs them, so it is worth to do them again. Please let us know if you miss something. But we added iterators, so you can loop over JSON arrays or objects with getting values, entries or child objects:

Dim o As New JSONMBS

o.add 1
o.add 2
o.add 3

For Each v As JSONMBS In o.Iterate
Break
// watch in debugger
Next

For Each v As JSONEntryMBS In o.IterateEntries
Break
// watch in debugger
Next
For Each v As Variant In o.IterateValues
Break
// watch in debugger
Next

If you use the Name property for a value in a JSON object, that will only work, if the link between parent and child objects is there. Then we lookup a name for a value by looking on the parent object. Otherwise the name will be blank. Same for Next and Previous node functions.

Please try 23.5pr5 or newer with our new class and let us know if you like it.
20 10 23 - 08:38