0

我有 json 字符串,它是由 server.php 生成的

[{"attr":{"id":"node_7","rel":"default"},"data":"doc.html","state":""},
 {"attr":{"id":"node_8","rel":"folder"},"data":"New node","state":"closed"},
 {"attr":{"id":"node_9","rel":"folder"},"data":"New node","state":""}]

如何删除包含该值的完整字符串rel=default

这是我为 server.php 编写的代码。

require_once("config.php");
$jstree = new json_tree();




echo $jstree->{$_REQUEST["operation"]}($_REQUEST);
die();
4

2 回答 2

1

使用 PHP:

// convert json string to array
$json = json_decode($json_string);

// filter out items
$json = array_filter($json, function($item)
{
    return $item->attr->rel != "default";
});

// convert back to string
$json_string = json_encode($json);
于 2012-07-06T14:23:25.327 回答
0

您可以使用 data.items.splice(X, Y); 删除一个元素;)

于 2012-07-06T14:25:09.013 回答