Answer the question
In order to leave comments, you need to log in
How to display data in Json in hierarchical form?
My JSON looks like this:
[
{
"id": "197",
"user_id": 471,
"position": "CEO",
"child_id_users": null
},
{
"id": "338",
"user_id": 342,
"position": "Deputy. director",
"child_id_users": "471"
},
{
"id": "411",
"user_id": 347,
"position": "Chief Accountant",
"child_id_users": "342"
},
{
"id": "543",
"user_id": 1003,
"position": "personal driver №1",
"child_id_users": "471"
},
{
"id": "521",
"user_id": 867,
"position": "personal driver №2",
"child_id_users": "342"
},
...
]
[
{
"id": "197",
"user_id": 471,
"position": "CEO",
"child_id_users": null,
"children": [{
{
"id": "338",
"user_id": 342,
"position": "Deputy. director",
"child_id_users": "471",
"children": [{
"id": "411",
"user_id": 347,
"position": "Chief Accountant",
"child_id_users": "342"
},
{
"id": "521",
"user_id": 867,
"position": "personal driver №2",
"child_id_users": "342"
}]
},
{
"id": "543",
"user_id": 1003,
"position": "personal driver №1",
"child_id_users": "471"
}
}]
}
]
def index
@org_charts = OrgChart.all
render json: JSON.pretty_generate(@org_charts.as_json)
end
Answer the question
In order to leave comments, you need to log in
So, what exactly do you need to get from there? In general, logically, you need data from data, then you need to do this:
$res = json_decode($result, true);
if ($res['success']) {
for($i = 0; $i < $res['totalNumRows']; $i++) {
$elem = $res['data'][$i]; //$elem и есть ваши данные далее делайте с ними что хотите
echo $elem['clicks'];//Выводим клики
}
} else {
//Тут обработка если получил false
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question