DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

工作中可能会遇到这种情况:想用json变量的内容但又不需要用全部,想把不需要的项删除掉。此时removeMember派上了用场。removeMember有好几个重载的版本,这里只讲3个常用的版本。

1,removeMember普通成员

 
 
void removeMember()
 
{
 
Json::Value Sample;
 
Sample["channel"] = 10;
 
Sample["format"] = "H264";
 
 
 
Json::Value del; //保存remove 项对应的值
 
Sample.removeMember("channel", &del);
 
printf("Sample = %s\ndel: %s\n", Sample.toStyledString().c_str(), del.toStyledString().c_str());
 
}
 
 

把channel项删除,结果:

2,removeMember 对象

 
 
void removeMember2()
 
{
 
Json::Value Sample;
 
Sample["channel"] = 10;
 
Sample["format"] = "H264";
 
 
 
Json::Value test;
 
test["info"] = Sample;
 
test["time"] = "134530943";
 
 
 
printf("test = %s\n", test.toStyledString().c_str());
 
 
 
Json::Value del; //保存remove 项对应的值
 
test.removeMember("info", &del);
 
printf("after remove = %s\n", test.toStyledString().c_str());
 
}
 
 

把info对象删除,结果:

3,removeMember 数组成员

 
 
void removeMember3()
 
{
 
Json::Value Sample;
 
Sample[0] = "0";
 
Sample[1] = "1";
 
Sample[2] = "2";
 
Sample[3] = "3";
 
printf("Sample = %s\n", Sample.toStyledString().c_str());
 
 
 
Json::Value del;
 
Sample.removeIndex(1, &del);
 
printf("after remove = %s\n", Sample.toStyledString().c_str());
 
}
 

把下标为1的数组元素删除,结果:

posted on   DoubleLi  阅读(134)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2022-02-23 shell脚本中一些特殊符号
2022-02-23 Linux tr命令使用方法
2022-02-23 Linux Shell脚本中获取本机ip地址方法
2022-02-23 grep -v、-e、-E
2021-02-23 WebRTC直播课堂实践:实时互动是核心
2021-02-23 WebRTC媒体协商及实践
2021-02-23 爱奇艺直播 WebAssembly 优化之路
点击右上角即可分享
微信分享提示