RapidJSON library getting a value inside an array by its index
c, c++, json
Solution
JSON
{"hi": "hellow", "first": {"next":[{"key":"important_value"} ] } }
Code:
rapidjson::Document document;
if (document.Parse<0>(json).HasParseError() == false)
{
const Value& a = document["first"];
const Value& b = a["next"];
// rapidjson uses SizeType instead of size_t.
for (rapidjson::SizeType i = 0; i < b.Size(); i++)
{
const Value& c = b[i];
printf("%s \n",c["key"].GetString());
}
}
Will print important_value
Problem
``` {"hi": "hellow", "first": {"next":[ {"key":"important_value"} ] } } ``` Accessing RapidJSON inside array: this works: `cout << "HI VALUE:" << variable["hi"].GetString() << endl;` this will output: `hellow` as expected, the problem is to access inside values like if I want to get "Important_Value", I tried something like this: `cout << "Key VALUE:" << variable["first"]["next"][0]["key"].GetString() << endl ;` but this doesn't work, I want to be able to get the "important_value" by the first item of the array, and in this case it's the `[0]` that is causing error. How do I do to get it by its index? I hope it's clear my explanation. Thanks in advance.