RapidJSON: Dokument erstellen und serialisieren
English
Deutsch
RapidJSON ist eine auf Geschwindigkeit optimierte JSON-Bibliothek - daher fehlen ihr einige Komfortfunktionen und eine einfach zu verwendende Dokumentation zur Erstellung von JSON-Dokumenten von Grund auf.
So können Sie ein Dokument erstellen:
rapidjson_doc_snippet.cpp
// Dokument generieren: {"text": "Hello JSON!"}
Document doc;
doc.SetObject(); // doc zu einem Objekt machen!
doc.AddMember("text", "Hello JSON!", doc.GetAllocator());Vollständiges Beispiel, das auf cout ausgibt:
rapidjson_full_example.cpp
#include <iostream>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <rapidjson/ostreamwrapper.h>
using namespace rapidjson;
using namespace std;
int main() {
// Dokument generieren: {"text": "Hello JSON!"}
Document doc;
doc.SetObject(); // doc zu einem Objekt machen!
doc.AddMember("text", "Hello JSON!", doc.GetAllocator());
// Auf stdout schreiben
OStreamWrapper out(cout);
Writer<OStreamWrapper> writer(out);
doc.Accept(writer);
}Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow