WsDataNode.inc in Web Service Data 7
File
modules/ws_services/includes/WsDataNode.inc
View source
<?php
class WsDataNode extends WsData {
public function accepts() {
return array(
'json',
);
}
protected function parse($data) {
$data = $this
->unwrap(json_decode($data));
foreach ($data as $name => $value) {
if (is_array($value)) {
foreach ($data[$name] as $lang => $list) {
if (is_array($list)) {
foreach ($list as $id => $val) {
if (is_array($val) and isset($val['value'])) {
$data[$name][$lang][$id] = $val['value'];
}
}
}
}
}
}
return $data;
}
private function unwrap($data) {
if (is_object($data)) {
$data = get_object_vars($data);
}
if (is_array($data)) {
foreach ($data as $k => $v) {
$data[$k] = $this
->unwrap($v);
}
}
return $data;
}
}