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

Cocos2d-x添加jsoncpp应该资料都有了,今天来讲讲数组的解析和拼装~

 

[cpp] view plain copy
 
 
 
  1. int main()  
  2. {  
  3. 数组创建与分析:  
  4. 例子一:  
  5. string strValue = "{\"ldh\":\"001\",\"gfc\":\"002\",\"yyj\":\"003\",\"andy\":[\"005\",\"123\",\"true\"]}";  
  6. Json::Reader read;  
  7. Json::Value value;  
  8. value["ldh"] = "001";  
  9. value["gfc"] = "002";  
  10. value["andy"].append( "005" );  
  11. value["andy"].append( "123" );  
  12. value["andy"].append( "true" );  
  13. //if( read.parse( strValue,value ) )  
  14. {  
  15. Json::Value val_array = value["andy"];  
  16. int iSize = val_array.size();  
  17. for ( int nIndex = 0;nIndex < iSize;++ nIndex )  
  18. {  
  19. cout<<val_array[nIndex]<<endl;  
  20. }  
  21. }  
  22.   
  23.   
  24. 例子二:  
  25. Json::Reader read;  
  26. Json::Value value;  
  27. value["ldh"] = "001";  
  28. value["gfc"] = "002";  
  29. Value item;  
  30. Value array;  
  31. item["andy1"] = "005";  
  32. array.append( item );  
  33. item["andy1"] = "123";  
  34. array.append( item );  
  35. item["andy1"] = "true";  
  36. array.append( item );  
  37. value["andy"] = array;  
  38. cout<<value.toStyledString()<<endl;  
  39. Json::Value val_array = value["andy"];  
  40. int iSize = val_array.size();  
  41. for ( int nIndex = 0;nIndex < iSize;++ nIndex )  
  42. {  
  43. cout<<val_array[nIndex]<<endl;  
  44. if ( !val_array[nIndex]["andy1"].isNull() )  
  45. {  
  46. cout<<val_array[nIndex]["andy1"]<<endl;  
  47. }  
  48. }  
  49.   
  50.   
  51. 例子三:  
  52. std::string strValue = "{\"name\":\"json\",\"array\":[{\"cpp\":\"jsoncpp\"},{\"java\":\"jsoninjava\"},{\"php\":\"support\"}]}";    
  53. Json::Value value;  
  54. Reader read;  
  55. if ( !read.parse( strValue,value ) )  
  56. {  
  57. return -1;  
  58. }  
  59. cout<<value.toStyledString()<<endl;  
  60. Json::Value val_array = value["array"];  
  61. int iSize = val_array.size();  
  62. for ( int nIndex = 0;nIndex < iSize;++ nIndex )  
  63. {  
  64. cout<<val_array[nIndex]<<endl;  
  65. if ( val_array[nIndex].isMember( "cpp" ) )  
  66. {  
  67. cout<<val_array[nIndex]["cpp"]<<endl;  
  68. }  
  69. }  
  70.   
  71. getchar();  
  72. return 0;  
  73. }  
posted on   DoubleLi  阅读(1565)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2017-08-07 [置顶][终极精简版][图解]Nginx搭建flv mp4流媒体服务器
2017-08-07 nginx 点播mp4方法
2017-08-07 NGINX 添加MP4、FLV视频支持模块
2017-08-07 用nginx搭建基于rtmp或者http的flv、mp4流媒体服务器
2017-08-07 obs nginx-rtmp-module搭建流媒体服务器实现直播 ding
2017-08-07 利用nginx搭建RTMP视频点播、直播、HLS服务器
2017-08-07 使用nginx搭建媒体点播服务器
点击右上角即可分享
微信分享提示