解析CommandMessage

时间:2024-05-01 19:52:51

Json 解析:

void CommandMessage::ParseCmdBody()
{
try
{
Json::Reader reader;
Json::Value root;
if (!reader.parse(util::cStringToString(m_strRecvMsgString), root))
{
LOG__(ERR, _T("Json parse failed."));
return;
} std:string Code = root.get("code", "").asString();
Json::Value bodyNode = root.get("body", "");
Json::Value mList = bodyNode.get("mlist", "");
if (mList.isArray())
{
int nSize = mList.size();
for (int i = ; i < nSize; i++)
{
Json::Value list = mList[i];
if (list.isObject())
{
std::string muteType = list.get("mute_type", "").asString();
m_mType = atoi(muteType.c_str());
Json::Value frontUser = list.get("front_user", "");
if (frontUser.isArray())
{
int nSize = frontUser.size();
for (int i = ; i < nSize; i++)
{
Json::Value List = frontUser[i];
Info userInfo;
if (List.isObject())
{
userInfo.m_userCode = List.get("code", "").asString(); }
m_mapUserInfo[userInfo.m_userCode] = userInfo;
}
}
}
}
} }
catch (...)
{
LOG__(ERR, _T("Json exception."));
}
}