我有 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();
最佳答案
使用 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);
关于php - 通过 jquery 或 php 删除 json 中包含值的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11364033/