I want to pick up data from the json, but i can not code it in scala, i can only write it in php, because it is very simple to use, but i have no idea how can i do the same thing in scala. please help me out.
{
"home": {
"type": "literal",
"options": {
"route": "\/",
"defaults": {
"controller": "Apiv1\\Controller\\Index",
"action": "index"
}
}
},
"praise": {
"type": "literal",
"options": {
"route": "\/apiv1\/praise",
"defaults": {
"controller": "Apiv1\\Controller\\Praise",
"action": "index"
}
},
"may_terminate": true,
"child_routes": {
"status": {
"type": "literal",
"options": {
"route": "\/status",
"defaults": {
"action": "status"
}
}
}
}
},
"admin": {
"type": "literal",
"options": {
"route": "\/admin",
"defaults": {
"controller": "Admin\\Controller\\Index",
"action": "index"
}
},
"may_terminate": true,
"child_routes": {
"routes": {
"type": "literal",
"options": {
"route": "\/routes",
"defaults": {
"controller": "Admin\\Controller\\Routes",
"action": "index"
}
},
"may_terminate": true,
"child_routes": {
"list": {
"type": "literal",
"options": {
"route": "\/list",
"defaults": {
"action": "list"
}
}
}
}
}
}
}
}
I want to pick up the route field from the json, and i would like to list all routes
here is my php version function
function parseRoute($a, $pre = '', &$urls)
{
foreach ($a as $k => $v) {
$route = $pre . $v['options']['route'];
$urls[] = $route;
if (isset($v['child_routes']) && is_array($v['child_routes'])) {
$this->parseRoute($v['child_routes'], $route, $urls);
}
$route = null;
}
}
$urls = array();
var_dump(parseRoute(json_decode($data), '', $urls));