Xojo Conferences
MBSOct2019CologneDE

Platforms to show: All Mac Windows Linux Cross-Platform

JSONMBS.AddItemToArray(item as JSONMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Adds an item to an array.
Notes:
If you add item from new nodes created with plugin, we add them to the tree.
If you add items from existing node from other JSON tree, we add references.

Feedback, Comments & Corrections

JSONMBS.AddItemToObject(label as string, value as JSONMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Adds an item to an object with given label.
Notes:
If you add item from new nodes created with plugin, we add them to the tree.
If you add items from existing node from other JSON tree, we add references.

Feedback, Comments & Corrections

JSONMBS.ArrayItem(index as Integer) as JSONMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Queries array item with given index.

Feedback, Comments & Corrections

JSONMBS.Child(label as string) as JSONMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Returns the Child node for the node with the given label.
Example:
dim jv as JSONMBS = JSONMBS.NewStringNode("value")
dim jo as JSONMBS = JSONMBS.NewObjectNode

jo.AddItemToObject("key", jv)

// shows {"key": "value"}
MsgBox jo.toString
MsgBox jo.Child("key").ValueString
Notes: Similar to JSONItem.Child()

Feedback, Comments & Corrections

JSONMBS.Clone as JSONMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 16.0 Yes Yes Yes Yes No
Function: Clones the JSON tree.

Feedback, Comments & Corrections

JSONMBS.Close
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 16.0 Yes Yes Yes Yes No
Function: Frees node.
Notes:
No need to call this as destructor does the same.
But this call allows you to release circular references.

Feedback, Comments & Corrections

JSONMBS.Constructor
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Creates an empty object.
Notes: Lasterror is set.

See also:

Feedback, Comments & Corrections

JSONMBS.Constructor(text as string)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Parses the given JSON String into the tree where this node is the root.
Example:
dim o as new JSONMBS("{""text"":""Hello World""}")
MsgBox o.toString
Notes:
Lasterror is set.
Text should be UTF-8.

Starting with version 15.0, you may see a ParseError and still have all the content which was parsed until that error.

See also:

Feedback, Comments & Corrections

JSONMBS.Convert as Variant
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.2 Yes Yes Yes Yes No
Function: Converts JSON object to Xojo variant.
Example:
// build some JSON:

Dim j As New JSONMBS

j.AddItemToObject "test", JSONMBS.NewNumberNode(123)
j.AddItemToObject "name", JSONMBS.NewStringNode("Joe")

// convert to Dictionary
Dim v As Variant = j.Convert

// and back
Dim o As JSONMBS = JSONMBS.Convert(v)

// show
MsgBox o.toString
Notes: Depending on the JSON content, you get variants containing values (string, double, boolean or nil), dictionaries or array of variants.

See also:

Feedback, Comments & Corrections

JSONMBS.DeleteItem(index as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.1 Yes Yes Yes Yes No
Function: Deletes an item from an array/object by index.
Example:
Dim j As New JSONMBS

j.AddItemToObject "Hello", j.NewStringNode("Testing")
j.AddItemToObject "World", j.NewStringNode("Another node")

MsgBox j.toString

// delete named item
j.DeleteItem "Hello"

MsgBox j.toString

// delete first item
j.DeleteItem 0

MsgBox j.toString
Notes: Index is zero based.

See also:

Feedback, Comments & Corrections

JSONMBS.DeleteItem(label as string)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.1 Yes Yes Yes Yes No
Function: Deletes a named item from an object.
Example:
Dim j As New JSONMBS

j.AddItemToObject "Hello", j.NewStringNode("Testing")
j.AddItemToObject "World", j.NewStringNode("Another node")

MsgBox j.toString

// delete named item
j.DeleteItem "Hello"

MsgBox j.toString

// delete first item
j.DeleteItem 0

MsgBox j.toString

See also:

Feedback, Comments & Corrections

JSONMBS.Equals(Other as JSONMBS) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.0 Yes Yes Yes Yes No
Function: Checks if two JSON are equal.
Example:
dim j1 as JSONMBS = JSONMBS.NewNumberNode(5)
dim j2 as JSONMBS = JSONMBS.NewNumberNode(5)
dim j3 as JSONMBS = JSONMBS.NewNumberNode(6)

if not j1.Equals(j2) then
break // failed
end if

if j3.Equals(j2) then
break // failed
end if

Break // okay
Notes:
We compare recursively all nodes.
If structure and values are the same, we return true, otherwise false.
Objects do not need to have same order for entries.

Feedback, Comments & Corrections

JSONMBS.FindValueInArray(Other as JSONMBS) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.0 Yes Yes Yes Yes No
Function: Queries index of value in array.
Example:
dim j1 as JSONMBS = JSONMBS.NewIntegerArray(array(3,4,5,6,7))
dim j2 as JSONMBS = JSONMBS.NewNumberNode(5)
dim j3 as JSONMBS = JSONMBS.NewNumberNode(8)
dim j4 as JSONMBS = JSONMBS.NewStringNode("5")

dim index1 as integer = j1.FindValueInArray(j2) // we can find this
dim index2 as integer = j1.FindValueInArray(j3) // value not found
dim index3 as integer = j1.FindValueInArray(j4) // can't find string in number array

if index1 = 2 and index2 = -1 and index3 = -1 then
Break // okay
else
Break // failed
end if
Notes: Returns zero based index or -1 if not found.

Feedback, Comments & Corrections

JSONMBS.FindValueInObjectArray(Name as String, Other as JSONMBS) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.0 Yes Yes Yes Yes No
Function: Queries index of value in object array.
Example:
dim j1 as JSONMBS = JSONMBS.NewArrayNode
dim j2 as JSONMBS = JSONMBS.NewObjectNode

j2.AddItemToObject "Hello", JSONMBS.NewStringNode("World")
j2.AddItemToObject "ID", JSONMBS.NewStringNode("123")

j1.AddItemToArray j2

dim index1 as integer = j1.FindValueInObjectArray("ID", JSONMBS.NewStringNode("123")) // we can find this
dim index2 as integer = j1.FindValueInObjectArray("ID", JSONMBS.NewStringNode("456")) // value not found
dim index3 as integer = j1.FindValueInObjectArray("xxx", JSONMBS.NewStringNode("123")) // value not found

if index1 = 0 and index2 = -1 and index3 = -1 then
Break // okay
else
Break // failed
end if
Notes:
Returns zero based index or -1 if not found.
We look into each object in the array, check if it has a value for the given label and compare that to the one to find.

Feedback, Comments & Corrections

JSONMBS.hasChild(label as string) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.5 Yes Yes Yes Yes No
Function: Checks if a child node for the node with the given label exists.
Example:
dim jv as JSONMBS = JSONMBS.NewStringNode("value")
dim jo as JSONMBS = JSONMBS.NewObjectNode

jo.AddItemToObject("key", jv)

// shows {"key": "value"}
MsgBox jo.toString
MsgBox str(jo.hasChild("key"))
Notes: Similar to JSONMBS.Child(), but without returning the actual objct.

Feedback, Comments & Corrections

JSONMBS.Sort
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 19.3 Yes Yes Yes Yes No
Function: Sorts the JSON array or object.
Example:
Dim j As JSONMBS = JSONMBS.NewDoubleArray(Array(123.0,3.1,3.2,5, -5))
j.Sort
MsgBox j.toString
Notes:
Sorts either array values or object key names.
If two values in array are both number in type, we compare the numeric values.

Feedback, Comments & Corrections

JSONMBS.SuffixObject(nextItem as JSONMBS) as JSONMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.5 Yes Yes Yes Yes No
Function: Appends an array item on a previous item in the same array.
Example:
// test code for SuffixObject:
const UseFastMode = true

dim o as JSONMBS = JSONMBS.NewArrayNode

dim startTime as Double = Microseconds
dim last as JSONMBS
for i as Integer = 0 to 10000

dim j as JSONMBS = JSONMBS.NewStringNode("test" + str(i))

#if UseFastMode = False
// slow
o.AddItemToArray(j)

#else
// 10 times faster

if last = nil then
o.AddItemToArray(j)
last = o.ChildNode
else
last = last.SuffixObject(j)
end if
#endif
next

dim endTime as Double = Microseconds

MsgBox (str(endTime - startTime))
Notes:
This method is an optimization for AddItemToArray.
You can call SuffixObject only on the last item of an array to add another one.
Only add new nodes there.
Any other use could lead into crashes or memory leaks.

Returns in version 16.0 and newer the new reference node.

Feedback, Comments & Corrections

JSONMBS.ToHTML(NoHeader as boolean = false, CSS as string = "") as String
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 18.2 Yes Yes Yes Yes No
Function: Converts JSON to HTML.
Notes:
We build for you a HTML with tables for each array and object. We include values and tag rows with even/odd CSS classes.
If NoHeader is true, you get just the raw table without header/footer.
Anything in CSS parameter is inserted before the table.
Returns HTML, which can be loaded in htmlviewer.

Example for CSS to do even/odd line backgrounds:

/* CSS style to include */
"<style>
td
{
vertical-align:top;
}

.odd
{
background-color: white;
}

.even
{
background-color: #DDD;
}
</style>"

Feedback, Comments & Corrections

JSONMBS.toString(formatted as boolean) as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method JavaScript Object Notation MBS Util Plugin 13.3 Yes Yes Yes Yes No
Function: Produces a JSON markup text document from a document tree.
Example:
dim o as JSONMBS = JSONMBS.NewObjectNode

o.AddItemToObject "text", JSONMBS.NewStringNode("Hello World")

MsgBox o.toString // shows "{"text":"Hello World"}"
Notes: Returns "" on any error. Lasterror is set.

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Util Plugin.

The biggest plugin in space...




Links
MBS Xojo PDF Plugins