Class JSONObject

Description

Based on properties added, this class is responsible for building a list of elements, and then generating a JSON string from those elements. This is more powerful than json_encode() in that it allows for adding arrays and objects as member variables to the JavaScript object.

Located in /class.jsonobject.php (line 26)


                
			
Method Summary
static string ConvertJSONAttributes (array $aAttributes, [string $sStartChar = '{'], [string $sEndChar = '}'])
JSONObject __construct ()
void AddAttribute (string $sKey, mixed $xValue)
array GetAttributes ()
string __toString ()
Methods
static method ConvertJSONAttributes (line 85)

Protected method for looping the supplied attributes and turning them into a JSON string.

This method is called recursively when a value of array or JSONObject is found in the provided attributes array

  • return: The JSON string for the provided elements
  • access: protected
static string ConvertJSONAttributes (array $aAttributes, [string $sStartChar = '{'], [string $sEndChar = '}'])
  • array $aAttributes: The array of elements to parse into JSON
  • string $sStartChar: Optional; The starting character of this JSON attribute, either { for an object or [ for an array. Default: {
  • string $sEndChar: The ending character of this JSON attribute, either } for an object or ] for an array. Default: }
Constructor __construct (line 37)

Constructor. Currently does nothing.

  • access: public
JSONObject __construct ()
AddAttribute (line 54)

Adds the specified key/value pair to our list of attributes in the JavaScript object.

key/value will be converted to { 'key': 'value } in JSON. The value parameter can be either a string, number (integer or float), array, or another JSONObject object. If an array is passed, it may also contain any of the previously listed types. Passed arrays and JSONObject objects will be recursively parsed.

  • access: public
void AddAttribute (string $sKey, mixed $xValue)
  • string $sKey: The key for this attribute of the JavaScript object
  • mixed $xValue: The value for this attribute of the JavaScript object, either a string, number or another JSONObject object may be passed.
GetAttributes (line 66)

Protected method to return the elements in this JSONObject

  • return: The array of elements stored in this object
  • access: protected
array GetAttributes ()
__toString (line 134)

Converts the object into a string by parsing the attributes array. This method calls the protected ConvertJSONAttributes method and returns its output

  • return: The JSON string for the attributes stored in this class
  • access: public
string __toString ()

Documentation generated on Thu, 25 Feb 2010 15:59:40 -0500 by phpDocumentor 1.4.3