Version 0.9.1
<?php
class JSON {
/*
$_GET['format'] = JSON | VAR
*/
//CONSTRUCTOR
public function __construct($nval = '') {
foreach($nval as $key => $val) {
$this->$key = $val;
}
}
//TO_STRING
public function __toString() {
$rstr = '';
$csv = '';
foreach($this as $key => $val) {
if($rstr != '') { $csv.= ','; $rstr .= ', '; }
$rstr .= '"'. $key .'": '. any2json($val);
$csv .= $val;
}
if($rstr == '') $rstr = '"Error": "No output defined"';
$format = aGET('format');
if($format->val == 'VAR') {
$out = 'var res = {'. $rstr .'}';
} elseif(strtoupper($format->val) == 'CSV') {
$out = $csv;
} else {
$out = '{'. $rstr .'}';
}
return $out;
}
}
?>