使用 jsoncpp,我正在创建一个 JSON 对象。
Json::Value root;
Json::Value zone1;
Json::Value coord;
Json::Value gridOrigin;
JSON_PEOPLE(){
zone1["zoneID"] = "shop1";
zone1["stamp"] = "##########";
zone1["gridSizeX"]=50;
zone1["gridSizeY"]=50;
zone1["gridScale"]=0.5;
zone1["gridOrigin"].append(28.5);
zone1["gridOrigin"].append(20.6);
}
std::string get_time_stamp()
{
time_t rawtime;
std::time(&rawtime);
struct tm *tinfo = std::localtime(&rawtime);
char buf[50];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tinfo);
return std::string(buf);
}
std::string updateZone (std::vector < std::pair <int,int> > &world_coords){
zone1["stamp"]=get_time_stamp();
coord.clear();
zone1["detected_people"].clear();
for(int i=0; i < world_coords.size(); i++){
Json::Value person;
person.append(world_coords[i].first);person.append(world_coords[i].second);
coord["coordinates"].append(person);
}
zone1["detected_people"] = coord;
root["zone1"]=zone1;
Json::StreamWriterBuilder builder;
const std::string json_file = Json::writeString(builder, root);
return json_file;
}
Run Code Online (Sandbox Code Playgroud)
我有错误root["zone1"]=zone1;
terminate called after throwing an instance of 'Json::LogicError'
what(): in Json::Value::resolveReference(key, end): requires objectValue
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)
可能出什么问题了?
| 归档时间: |
|
| 查看次数: |
3366 次 |
| 最近记录: |