#include "rapidjson/document.h" using namespace rapidjson; int main() { const char* json = "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}"; Document doc; doc.Parse(json); if (doc.IsObject()) { printf("The JSON value is an object.\n"); } else { printf("The JSON value is not an object.\n"); } return 0; }
#include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" using namespace rapidjson; int main() { Document doc; doc.SetObject(); Value name; name.SetString("John", doc.GetAllocator()); doc.AddMember("name", name, doc.GetAllocator()); if (doc.IsObject()) { printf("The JSON value is an object.\n"); } else { printf("The JSON value is not an object.\n"); } StringBuffer buffer; WriterIn this example, a new JSON object is created using RapidJSON's Document class and the SetObject function. Then, a string value is added to the object using the AddMember function. Finally, the IsObject function is used to check whether the resulting value is an object, and the JSON is output to the console using RapidJSON's Writer class.writer(buffer); doc.Accept(writer); printf("%s\n", buffer.GetString()); return 0; }