I have a complex JSON to load into a data structure in C++11 and I got high recommendations about RapidJSON. I need to iterate over a complex JSON and looked around for answers on how to do it. The best answer I found was in this thread.
However, there's a small glitch in matching this solution to mine, I have members in the JSON that have different names but identical content:
"responsibilities": {
"starters_reciepe": {
"name": "bok choi salad",
"type": "veggie",
"ingredients": {
"leafyIng": "bok choi",
"proteinIng": "tofu",
"seasoning": [
{
"2 tsp": "salt",
"1 tsp": "turmric"
}
]
}
},
"mainCourse_reciepe": {
"name": "pad tai",
"type": "yum yum",
"ingredients": {
"leafyIng": "chard",
"proteinIng": "soylent green"
"seasoning": [
{
"2 tsp": "black pepper",
"1 tsp": "tears of the angels"
}
]
}
}
}
Basically, I need to go over the content of the ingredients, but I can't get over the fact that starters_reciepe is not like mainCourse_reciepe.
EDITED: Here's my code:
Document d;
ifstream in("TestingJSON.json", ios::binary);
if (!in)
throw runtime_error("Failed to open file");
istreambuf_iterator<char> head(in);
istreambuf_iterator<char> tail;
string data(head, tail);
d.Parse(data.c_str());
const Value& prog = d["responsibilities"];
for (Value::ConstValueIterator p = prog.Begin(); p != prog.End(); ++p) {
cout << (*p)["iUniqueID"].GetString()<<endl;
const Value& inFiles = (*p)["inFiles"];
for (Value::ConstValueIterator inFile = inFiles.Begin(); inFile != prog.End(); ++inFile) {
cout << (*inFile)["sFileType"].GetString() << endl;
cout << (*inFile)["pos"]["x1"].GetInt() << endl;
}
}
Can I use wildcards and write *_reciepe?
I could find anything on RapidJSON and wildcards. Is this even a possibility?