-2
如何解析XML並獲取節點。解析XML並取消設置節點
如何解析XML並獲取節點。解析XML並取消設置節點
你可以使用json_decode
字符串解碼,一個遞歸函數刪除所有不活動的元素,最後json_encode
恢復數組的JSON字符串
$json = json_decode($data, true);
$json['categoryTree'] = filter_inactive($json['categoryTree']);
echo json_encode($json);
function filter_inactive($data) {
$t = array();
foreach ($data as $child) {
if ($child['is_active'] == '1') {
if (isset($child['children'])) {
$child['children'] = filter_inactive($child['children']);
}
$t[] = $child;
}
}
return $t;
}
謝謝你的工作f9 – 2014-09-08 19:01:46
你嘗試過什麼?你的標籤很混亂 - node.js與事物有什麼關係? – Steve 2014-09-05 11:48:56
試過json_decode()? – Nutic 2014-09-05 11:51:25
使用解碼json和遞歸樹迭代器 – inf3rno 2014-09-05 11:54:16