c++ CJsonObject 库解析json

#include "CJsonObject.hpp"


//CJsonObject下载地址    https://github.com/Bwar/CJsonObject

//json解析
		neb::CJsonObject json;

		if (json.Parse(dataStr)) //解析成功返回true
		{
			CELLLog_Info(" CJsonObject Parse Succeed. ");

		/*	int msgid=0;
			if (!json.Get("msgId", msgid))
			{
				CELLLog_Info(" Not Found  msgid ");
			}

			time_t time = 0;
			if (!json.Get("time", time))
			{
				CELLLog_Info(" Not Found  time ");
			}
			std::string data = json("data");*/

			/*cJSON_GetArrayItem(json,);
			cJSON_Parse()*/


			CELLLog_Info(" GetArraySize  %d ", json.GetArraySize());

			//获取数组
			// [1,1591695770646,"hello"]
			int msgId=0;
			if (! json.Get(0, msgId))
			{
				CELLLog_Info(" Not Found  msgid ");
			}
			else
			{
				CELLLog_Info(" msgId  %d ", msgId);
			}

			time_t time = 0;
			if (!json.Get(1, time))
			{
				CELLLog_Info(" Not Found  time ");
			}
			else
			{
				CELLLog_Info(" msgId  %lld ", time);
			}
			std::string data;
			if (!json.Get(2, data))
			{
				CELLLog_Info(" Not Found  data ");
			}
			else
			{
				CELLLog_Info(" data  %s ", data.c_str());
			}
		}
		else
		{
			CELLLog_Info("json.Parse failed.%s",json.GetErrMsg().c_str());
		}
		

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值