~fabiocbalbuquerque/sahana-agasti/web-services

« back to all changes in this revision

Viewing changes to web/wiki/inc/JSON.php

  • Committer: Chad Heuschober
  • Date: 2011-06-06 13:37:45 UTC
  • mfrom: (1.1.1244 trunk)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: chad.heuschober@mail.cuny.edu-20110606133745-850mdvnjtv392zta
Pulled in most recent batch of changes from the cuny sps trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
 * @deprecated
113
113
 */
114
114
class JSON {
 
115
 
 
116
    /**
 
117
     * Disables the use of PHP5's native json_decode()
 
118
     *
 
119
     * You shouldn't change this usually because the native function is much
 
120
     * faster. However, this non-native will also parse slightly broken JSON
 
121
     * which might be handy when talking to a non-conform endpoint
 
122
     */
 
123
    public $skipnative = false;
 
124
 
115
125
    /**
116
126
     * constructs a new JSON instance
117
127
     *
130
140
 
131
141
    /**
132
142
     * encodes an arbitrary variable into JSON format
 
143
     * If available the native PHP JSON implementation is used.
133
144
     *
134
145
     * @param    mixed   $var    any number, boolean, string, array, or object to be encoded.
135
146
     *                           see argument 1 to JSON() above for array-parsing behavior.
140
151
     * @access   public
141
152
     */
142
153
    function encode($var) {
 
154
        if (function_exists('json_encode')) return json_encode($var);
143
155
        switch (gettype($var)) {
144
156
            case 'boolean':
145
157
                return $var ? 'true' : 'false';
352
364
 
353
365
    /**
354
366
     * decodes a JSON string into appropriate variable
 
367
     * If available the native PHP JSON implementation is used.
355
368
     *
356
369
     * @param    string  $str    JSON-formatted string
357
370
     *
363
376
     * @access   public
364
377
     */
365
378
    function decode($str) {
 
379
        if (!$this->skipnative && function_exists('json_decode')){
 
380
            return json_decode($str,($this->use == JSON_LOOSE_TYPE));
 
381
        }
 
382
 
366
383
        $str = $this->reduce_string($str);
367
384
 
368
385
        switch (strtolower($str)) {