I'm trying to print from a JSON only the values that matching some keys:
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
using namespace rapidjson;
char* kTypeNames[] = { "First", "text", "print", "key" };
int main() {
// 1. Parse a JSON string into DOM.
const char json[] =
" { \"First\" : \"a\", \"text\" : \"b\" ,\"key\" : \"hello\" ,
\"print\" : \"1\",\"print\" : \"2\",\"no_key\" : \"2\"} ";
// ...
Document document;
document.Parse(json);
printf(json);
printf("\nAccess values in document:\n");
assert(document.IsObject());
for (Value::ConstMemberIterator itr = document.MemberBegin();
itr !=document.MemberEnd(); ++itr)
{
//how to print element that matches with kTypeNames array?
}
}
Keys needed are First, text, print and key, and I want to ignore no_key value. So I want to print only a, b, hello, 1 and do not print 2.
I'm looking and the documentation trying to find out how to do it.
Thanks