<?php
$j = '{"data":{"lan":[{"name":"Primary LAN Eth"},{"ip_address":"192.168.10.2"}]}}';
$jd = json_decode($j);
// var_dump($jd);
function quote($v) {
return '"'.$v.'"';
}
function bracket($v) {
return '{'.$v.'}';
}
// Convert a decoded JSON object back into a JSON string, but ignore arrays for cradlepoint
function stringify($v) {
$str = "";
switch(gettype($v)) {
case 'array':
for ($i = 0; $i < count($v); $i++)
$str .= ($i == 0 ? '':',').quote($i).':'.stringify($v[$i]);
$str = bracket($str);
break;
case 'object':
$c = '';
foreach ($v as $k=>$v) {
$str .= $c.quote($k).':'.stringify($v);
$c = ',';
}
$str = bracket($str);
break;
case 'boolean':
$str .= ($v ? 'true' : 'false');
break;
case 'integer':
case 'double':
$str .= ''.$v;
break;
case 'string':
$str .= quote($v);
break;
case 'NULL':
$str .= 'null';
break;
default:
break;
}
return $str;
}
echo stringify($jd);
?>
- Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- {"data":{"lan":{"0":{"name":"Primary LAN Eth"},"1":{"ip_address":"192.168.10.2"}}}}
- Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
- Fatal error: Call to undefined function json_decode() in /in/2iNYm on line 4
Process exited with code 255. - Output for 4.4.5 - 4.4.9
- Fatal error: Call to undefined function: json_decode() in /in/2iNYm on line 4
Process exited with code 255. - Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
- Fatal error: Call to undefined function: json_decode() in /in/2iNYm on line 4
Process exited with code 255. - Output for 4.3.0 - 4.3.1
- Fatal error: Call to undefined function: json_decode() in /in/2iNYm on line 4
preferences:
214.7 ms | 401 KiB | 314 Q