头像

java实现替换json字符串参数值

以下是代码:

String str="{\"code\":\"na7ne\",\"identity\":1671760031645,\"password\":\"88888888\",\"username\":\"fuj\"}";
JSONObject jsonObject = JSON.parseObject(str);
System.out.println(str);
for(Map.Entry<String,Object> map: jsonObject.entrySet()){
    if(map.getKey().contains("password"))
        JSONPath.set(jsonObject,"$."+map.getKey(),"***");
}
System.out.println(jsonObject.toJSONString());

以下是输出内容:

{"code":"na7ne","identity":1671760031645,"password":"88888888","username":"fuj"}
{"password":"***","code":"na7ne","identity":1671760031645,"username":"fuj"}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>