C++ JsonCpp用法

数据压缩:
int CRHTraderServerUnitApi::OnRspOpenAuth(CB2BRspOpenAuthFeildEX* pRspFieldEX)
{
Json::Value root;


if (strlen(pRspFieldEX->FlagField.DeviceUUID)>0 )
{
Json::Value FlagInfo;
JsonPackFlagInfo(&(pRspFieldEX->FlagField),FlagInfo);
root["pRspFieldEX"]=FlagInfo;
}
if (pRspFieldEX->ErrorField.ErrorID ==0 )
{
Json::Value Text;
///经纪公司代码
Text["BrokerID"] =pRspFieldEX->RspField.BrokerID;
///投资者代码
Text["InvestorID"] =pRspFieldEX->RspField.InvestorID;
///权限类型
Text["AuthorityID"] =pRspFieldEX->RspField.AuthorityID;
///交易柜台IP地址
Text["CounterFrontAddress"] =pRspFieldEX->RspField.CounterFrontAddress;


root["text"]=Text;
}
///请求编号
root["nRequestID"] =pRspFieldEX->nRequestID;
///是否是最后一条
root["bIsLast"] =pRspFieldEX->bIsLast;


if (pRspFieldEX->ErrorField.ErrorID != 0 )
{
Json::Value ErrInfo;
JsonPackErrorInfo(&(pRspFieldEX->ErrorField),ErrInfo);
root["errinfo"]=ErrInfo;
}
std::string strData = root.toStyledString();
Rohon_String* pStrSend = JSONPackString(strData.c_str(), strData.length(),RespRH_IB2B_OpenAuth);
int nSendLen = pStrSend->length();
LOG_TRACE(LOG_DEBUG_LEVEL,"RSPOPENAUTH","SendMsg:0x%08x",RespRH_IB2B_OpenAuth);
int nRet = SendData(pStrSend);
delete pStrSend;
return RETURN_OK;
}
数据解析:
CB2BReqOpenAuthFeildEX* CRHTraderServerUnitApi::JsonUnpackOpenAuth(char* pData,int nLen)
{
CB2BReqOpenAuthFeildEX* pField = NULL;
Json::Reader reader;
Json::Value root;
if (reader.parse(pData, root, true))
{
pField = new CB2BReqOpenAuthFeildEX;
memset(pField,0,sizeof(CB2BReqOpenAuthFeildEX));
std::string strParam;
///标识信息
if (!root["flaginfo"].isNull())
{
Json::Value JsonFlagInfo=root["flaginfo"];
JsonUnpackFlagInfo(&(pField->FlagField),JsonFlagInfo);
}
if (!root["text"].isNull())
{
Json::Value JsonText=root["text"];
CB2BReqOpenAuthFeild* pOpenAuthFeild =&(pField->ReqField);
memset(pOpenAuthFeild, 0, sizeof(CB2BReqOpenAuthFeild));


///经纪公司代码
if (!JsonText["BrokerID"].isNull())
{
strParam.clear();
strParam = JsonText["BrokerID"].asString();
strcpy(pOpenAuthFeild->BrokerID, strParam.c_str());
}
///投资者代码
if (!JsonText["InvestorID"].isNull())
{
strParam.clear();
strParam = JsonText["InvestorID"].asString();
strcpy(pOpenAuthFeild->InvestorID, strParam.c_str());
}
///权限类型
if (!JsonText["AuthorityID"].isNull())
{
pOpenAuthFeild->AuthorityID = JsonText["AuthorityID"].asInt();
}
///密码
if (!JsonText["Password"].isNull())
{
strParam.clear();
strParam = JsonText["Password"].asString();
strcpy(pOpenAuthFeild->Password, strParam.c_str());
}
///交易柜台IP地址
if (!JsonText["CounterFrontAddress"].isNull())
{
strParam.clear();
strParam = JsonText["CounterFrontAddress"].asString();
strcpy(pOpenAuthFeild->CounterFrontAddress, strParam.c_str());
}
}
///请求编号
if (!root["nRequestID"].isNull())
{
strParam.clear();
pField->nRequestID = root["nRequestID"].asInt();
}
}
return pField;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值