Cocos2d-x添加jsoncpp应该资料都有了,今天来讲讲数组的解析和拼装~
- int main()
- {
- 数组创建与分析:
- 例子一:
- string strValue = "{\"ldh\":\"001\",\"gfc\":\"002\",\"yyj\":\"003\",\"andy\":[\"005\",\"123\",\"true\"]}";
- Json::Reader read;
- Json::Value value;
- value["ldh"] = "001";
- value["gfc"] = "002";
- value["andy"].append( "005" );
- value["andy"].append( "123" );
- value["andy"].append( "true" );
- //if( read.parse( strValue,value ) )
- {
- Json::Value val_array = value["andy"];
- int iSize = val_array.size();
- for ( int nIndex = 0;nIndex < iSize;++ nIndex )
- {
- cout<<val_array[nIndex]<<endl;
- }
- }
- 例子二:
- Json::Reader read;
- Json::Value value;
- value["ldh"] = "001";
- value["gfc"] = "002";
- Value item;
- Value array;
- item["andy1"] = "005";
- array.append( item );
- item["andy1"] = "123";
- array.append( item );
- item["andy1"] = "true";
- array.append( item );
- value["andy"] = array;
- cout<<value.toStyledString()<<endl;
- Json::Value val_array = value["andy"];
- int iSize = val_array.size();
- for ( int nIndex = 0;nIndex < iSize;++ nIndex )
- {
- cout<<val_array[nIndex]<<endl;
- if ( !val_array[nIndex]["andy1"].isNull() )
- {
- cout<<val_array[nIndex]["andy1"]<<endl;
- }
- }
- 例子三:
- std::string strValue = "{\"name\":\"json\",\"array\":[{\"cpp\":\"jsoncpp\"},{\"java\":\"jsoninjava\"},{\"php\":\"support\"}]}";
- Json::Value value;
- Reader read;
- if ( !read.parse( strValue,value ) )
- {
- return -1;
- }
- cout<<value.toStyledString()<<endl;
- Json::Value val_array = value["array"];
- int iSize = val_array.size();
- for ( int nIndex = 0;nIndex < iSize;++ nIndex )
- {
- cout<<val_array[nIndex]<<endl;
- if ( val_array[nIndex].isMember( "cpp" ) )
- {
- cout<<val_array[nIndex]["cpp"]<<endl;
- }
- }
- getchar();
- return 0;
- }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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搭建媒体点播服务器