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());
		}
		////////////////////

 

你可能感兴趣的:(C++)