json数据:
{
"api":"setDatas",
"apiVer" : 0,
"packSn" : 0,
"operate" : "command",
"option" : ["none"],
"param" : {
"id": 1,
"datas": [1, 2, 3, 4, 5, 6]
},
"endFlg":"api"
}
接收函数:
CMDFN(setDatas)
{
int id;
int datas[256];
cmd["param"].Get("id",id);
int len = cmd["param"]["datas"].GetArraySize();
for(int i=0;i<len;i++) {
// cmd["param"].Get(i,datas[i]); 错
// cmd["param"].Get("datas"[i], datas[i]); 错
cmd["param"]["datas"].Get(i, datas[i]);
}
ack.Replace("param",1);
ack.ReplaceWithNull("option");
ack.Replace("srxApi",cmd("api"));
ack.Replace("packSn",cmd("packSn"));
return 0;
}
{
vector<int> list = {1, 2, 3, 4};
CJsonObject data;
data.AddEmptySubArray("param");
for(int i = 0; i< list.size(); i++) {
data["param"].Add(list[i]);
}
cout<< list.size()<<data["param"].GetArraySize()<<endl;
ack.Replace("param",data["param"]);
ack.ReplaceWithNull("option");
ack.Replace("srxApi",cmd("srxApi"));
ack.Replace("packSn",cmd("packSn"));
}
// param 打印 [1, 2, 3, 4];
// --------------------------------------------------
char list[20*1024];
vector<int> arr;
CJsonObject data;
data.AddEmptySubArray("param");
for(int i = 0; i< 20*1024; i++) {
arr.push_back(list[i]);
}
// --------------------------------------------------
json数据: {"param" : 1}
// 获取
int id;
cmd.Get("param", id);
CJsonObject data;
data.AddEmptySubArray("param");
for(int i = 0;i < 2;i++) {
CJsonObject obj;
obj.Add("url", "127.0.0.1");
obj.Add("str", "111");
data["param"].Add(obj);
}