Json::Value::resolveReference(key, end): requires objectValue

Viewed 1738

Using jsoncpp, I am creating a JSON object.

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

I have error at root["zone1"]=zone1;

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

What could be wrong?

0 Answers
Related