Json :: Value :: resolveReferencekey,end:需要objectValue

问题描述

使用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;      
   }

我在root["zone1"]=zone1;处出错

terminate called after throwing an instance of 'Json::LogicError'
  what():  in Json::Value::resolveReference(key,end): requires objectValue
Aborted (core dumped)

有什么问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)