rapidjson
程序员文章站
2024-02-04 08:26:52
...
Document document;
if (document.Parse(req_buf).HasParseError())
{
printf("parse URL Body err,info = %s",req_buf);
return ;
}
const char* szOptType = document["optType"].GetString();
if (szOptType == NULL)
{
printf("Recv Body Data Err ,optType is NULL");
return ;
}
for(int i = 0;i< document["camera"].Size() ;i++)
{
const char* szAddr = document["camera"][i]["address"].GetString();
const char* szPort = document["camera"][i]["port"].GetString();
const char* szUser = document["camera"][i]["username"].GetString();
const char* szPwd = document["camera"][i]["passwd"].GetString();
}
{
"optType":"1",
"camera":[
{
"address":"10.20.147.128",
"port":"8000",
"username":"admin",
"passwd":"123"
},
{
"address":"10.67.177.161",
"port":"8000",
"username":"admin",
"passwd":"123"
}
}
StringBuffer s;
Writer<StringBuffer> writer(s);
int size = ErrDevMsg.size();
writer.StartObject();
writer.Key("code");
if (size == 0) //如果没有一个是添加失败
{
writer.String(to_string(0).c_str());
writer.Key("msg");
writer.String("200 OK");
writer.EndObject();
}
else
{
writer.String(to_string(DAG_CAMERA_ERROR).c_str());
writer.Key("msg");
writer.String("Add Or Delete Error");
writer.Key("data");
writer.StartObject();
writer.Key("ErrDevInfo");
writer.StartArray();
for(std::map<string ,int>::iterator itor = ErrDevMsg.begin() ;itor != ErrDevMsg.end();itor++)
{
writer.StartObject();
writer.Key("indexCode");
writer.String(itor->first.c_str());
writer.Key("errcode");
writer.String(to_string(itor->second).c_str());
writer.EndObject();
}
writer.EndArray();
writer.EndObject();
writer.EndObject();
}
std::string strResult = s.GetString();
上一篇: RapidJSON
下一篇: leetcode143重排链表