[alibaba/fastjson]JSONPath remove $..abc 不生效

2025-10-28 139 views
0
<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.58</version>
        </dependency>

JSONPath删除带"$..abc"失败,为什么?

@Test
    public void testJson() {
        JSONObject father = new JSONObject();
        JSONObject children = new JSONObject();
        children.put("abc", "123");
        father.put("name", children);
        System.out.println();
        System.out.println(father);
        System.out.println(JSONPath.remove(father, "$..abc"));
        System.out.println(father);
    }
输出为: {"name":{"abc":"123"}} false {"name":{"abc":"123"}}

期望输出: {"name":{"abc":"123"}} true {"name":{}}

回答

6

root对象没有使用过,手误了吧 System.out.println(JSONPath.remove(js, "$..abc"));

8

root对象没有使用过,手误了吧 System.out.println(JSONPath.remove(js, "$..abc"));

test写错误

7

最新版本上面,是可以删除掉的,输出如下:

{"name":{"abc":"123"}}
false
{"name":{}}