Classic ASP Framework
org.classicasp.primitive.ObjectEx

The ObjectEx class is essentially an associative array that can have properties assigned to it dynamically. This class will accept a JSON encoded object.

To create a ObjectEx object, you can use the constructor or the global function, or assign a literal value.

Example 1

	
  Response.Write ObjectEx("{'name':'My Object', 'color':'red', 'size':'small', 'characters':'~!@#$%^&*()_+'}").toUrlData().toJSON()
  

Example 1 Output

"name=My+Object&color=red&size=small&characters=%7E%21%40%23%24%25%5E%26%2A%28%29%5F%2B"

Example 2 (Iterate ObjectEx with For Each)

  Dim oObject : Set oObject = ObjectEx("{'name':'My Object', 'color':'red', 'size':'small'}")
  Dim sItem, oItem
  

For Each sItem In oObject.GetItems.value

Set oItem = oObject(sItem) Response.write oItem.toString & "<hr>"

Next

Summary

Removes any items in the object that are not in the input.
Clones the current object.
Removes empty and null items in the object.
Deletes an item from the object.
Deletes all items from the object.
Flattens the object and returns all endpoints.
Expands the object and returns all subvalues as nodes.
Executes a test function on each item in the object and constructs a new object for all items that return true for the specified function.
Flattens the object and returns all subvalues.
Executes a function on each item in the object and returns a new object.
Gets the value of an item in the object.
Gets the number of items in the object.
Gets the names of the items in the object.
Gets the names of the items and children items in the object.
Deterimines if the object has an item.
Determines if the object has any items with values set.
Gets the number of items in the object.
Loads Application values into a new object.
Loads Request_Form values into a new object.
Loads Object values into the current object and returns a new object.
Loads Request_Form, Request_QueryString, and UploadUtil_Form values into a new object.
Loads Request_QueryString values into a new object.
Loads REST values into a new object.
Loads Request_ServerVariables values into a new object.
Loads Session values into a new object.
Loads global and local variables values into a new object.
Removes any items in the object that are in the input.
Removes all items in the object.
Renames items in the object, prepending the input to the item names.
Sets the value of an item in the object.
Sets the value of an item in the object, allows the use of a dot (.
Adds up the values in the object.
Converts unicode characters to ascii characters.
Returns a Bencoded string representation of the object.
Escapes special characters in the unescaped_object, so that it is safe to place it in a query.
Converts text to html and encodes special characters in text to html encoding.
Decodes special characters in the object items to html encoding.
Encodes special characters in the object items to html encoding.
Returns a json encoded string representation of the object.
Removes any items in the object that start with an underscore (_).
Returns a string representation of the object.
Converts the object to a string using the GET method for a url.
Returns an XML encoded string representation of the object.
Writes a json encoded string representation of the object.
Writes an XML encoded string representation of the object.

clean

Public Function clean(ByRef vInputFields)
Removes any items in the object that are not in the input.

Returns

ObjectEx

Example

		
	  Response.Write ObjectEx("{'name':'My Object', 'color':'red'}").clean("name").toJSON()
	  

Output

{"name":"My Object"}

clone

Public Function clone()
Clones the current object.

Returns

ObjectEx

compact

Public Function compact()
Removes empty and null items in the object.

Returns

ObjectEx

deleteItem

Public Sub deleteItem(ByVal sInputName)
Deletes an item from the object.

Returns

N/A

deleteItems

Public Sub deleteItems()
Deletes all items from the object.

Returns

N/A

endpoints

Public Function endpoints()
Flattens the object and returns all endpoints.

Returns

ObjectEx

expand

Public Function expand()
Expands the object and returns all subvalues as nodes. (opposite of flatten)

Returns

ObjectEx

filter

Public Function filter(ByVal vInputValue)
Executes a test function on each item in the object and constructs a new object for all items that return true for the specified function. If an item returns false, it is not included in the new object.

This function does not work within the context of a class.

Returns

ObjectEx

Example

		
	  

Output

flatten

Public Function flatten()
Flattens the object and returns all subvalues.

Returns

ObjectEx

forEach

Public Function forEach(ByVal vInputValue)
Executes a function on each item in the object and returns a new object.

Returns

ObjectEx

getItem

Public Function getItem(ByVal sInputName)
Gets the value of an item in the object.

Returns

Variant

getItemCount

Public Function getItemCount()
Gets the number of items in the object.

Returns

NumberEx

getItems

Public Function getItems()
Gets the names of the items in the object.

Returns

ArrayEx

getItemsChildren

Public Function getItemsChildren()
Gets the names of the items and children items in the object.

Returns

ArrayEx

hasItem

Public Function hasItem(ByVal sInputName)
Deterimines if the object has an item.

Returns

BooleanEx

isEmpty

Public Function isEmpty()
Determines if the object has any items with values set.

Returns

BooleanEx

length

Public Function length()
Gets the number of items in the object.

Returns

NumberEx

loadApplication

Public Function loadApplication()
Loads Application values into a new object.

Returns

ObjectEx

loadForm

Public Function loadForm()
Loads Request_Form values into a new object.

Returns

ObjectEx

loadObject

Public Function loadObject(ByVal oInputObject)
Loads Object values into the current object and returns a new object.

Returns

ObjectEx

loadParameters

Public Function loadParameters()
Loads Request_Form, Request_QueryString, and UploadUtil_Form values into a new object.

Returns

ObjectEx

loadQueryString

Public Function loadQueryString()
Loads Request_QueryString values into a new object.

Returns

ObjectEx

loadRest

Public Function loadRest()
Loads REST values into a new object.

Returns

ObjectEx

loadServerVariables

Public Function loadServerVariables()
Loads Request_ServerVariables values into a new object.

Returns

ObjectEx

loadSession

Public Function loadSession()
Loads Session values into a new object.

Returns

ObjectEx

loadVariables

Public Function loadVariables(ByVal vInputVariables)
Loads global and local variables values into a new object.

Returns

ObjectEx

remove

Public Function remove(ByRef vInputFields)
Removes any items in the object that are in the input.

Returns

ObjectEx

Example

		
	  Response.Write ObjectEx("{'name':'My Object', 'color':'red'}").remove("name").toJSON()
	  

Output

{"color":"red"}

removeAll

Public Function removeAll()
Removes all items in the object.

Returns

ObjectEx

rename

Public Function rename(ByRef sInput)
Renames items in the object, prepending the input to the item names.

Returns

ObjectEx

setItem

Public Sub setItem(
ByVal sInputName,
ByRef sInputValue)
Sets the value of an item in the object.

Returns

N/A

setItemEx

Public Sub setItemEx(
ByVal sInputName,
ByRef sInputValue)
Sets the value of an item in the object, allows the use of a dot (.) to set subfields.

Returns

N/A

sum

Public Function sum()
Adds up the values in the object.

Returns

StringEx

toAscii

Public Function toAscii()
Converts unicode characters to ascii characters.

Returns

ObjectEx

toBencode

Public Function toBencode()
Returns a Bencoded string representation of the object.

Returns

String

Example

		
	  Response.Write ObjectEx("{'name':'My Object'}").toBencode()
	  

Output

d4:name9:My Objecte

toEscapeSql

Public Function toEscapeSql()
Escapes special characters in the unescaped_object, so that it is safe to place it in a query.

Returns

ObjectEx

toHtml

Public Function toHtml()
Converts text to html and encodes special characters in text to html encoding.

Returns

ObjectEx

toHtmlDecode

Public Function toHtmlDecode()
Decodes special characters in the object items to html encoding.

Returns

ObjectEx

toHtmlEncode

Public Function toHtmlEncode()
Encodes special characters in the object items to html encoding.

Returns

ObjectEx

toJSON

Public Function toJSON()
Returns a json encoded string representation of the object.

Returns

String

Example

		
	  Response.Write ObjectEx("{'name':'My Object'}").toJSON()
	  

Output

{"name":"My Object"}

toSafe

Public Function toSafe()
Removes any items in the object that start with an underscore (_).

Returns

ObjectEx

Example

		
	  Response.Write ObjectEx("{'name':'My Object', '_private':'this is it'}").toSafe().toJSON()
	  

Output

{"name":"My Object"}

toString

Public Function toString()
Returns a string representation of the object.

Returns

StringEx

toUrlData

Public Function toUrlData()
Converts the object to a string using the GET method for a url. Item names and values are url encoded.

Returns

StringEx

Example

		
	  Response.Write ObjectEx("{'name':'My Object'}").toUrlData()
	  

Output

name=My+Object

toXML

Public Function toXML()
Returns an XML encoded string representation of the object.

Returns

String

Example

		
	  Response.Write ObjectEx("{'name':'My Object'}").toXML()
	  

Output

<data type="Object"><name type="String">My Object</name></data>

writeJSON

Public Sub writeJSON()
Writes a json encoded string representation of the object.

Returns

N/A

Example

		
	  Call ObjectEx("{'name':'My Object'}").writeJSON()
	  

Output

{"name":"My Object"}

writeXML

Public Sub writeXML()
Writes an XML encoded string representation of the object.

Returns

N/A

Example

		
	  Call ObjectEx("{'name':'My Object'}").writeXML()
	  

Output

<data type="Object"><name type="String">My Object</name></data>

'***ClassicASP.org
'Copyright 2010 ClassicASP.org

'This file is part of ClassicASP Framework.

'ClassicASP-Framework is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, version 3 of the License.

'ClassicASP-Framework is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with ClassicASP-Framework. If not, see .

'For additional information please visit .

Created with TwinText