get array data from json file using rapidjson
Finally found it myself, The correct syntax would be document["points"][0]["x"].GetString()
for (SizeType i = 0; i < document["points"].Size(); i++){
CCLOG("{x=%f, y=%f}", document["points"][i]["x"].GetDouble(), document["points"][i]["y"].GetDouble());
}
and the output is
Cocos2d: {x=-2.250000, y=-14.250000}
Cocos2d: {x=-5.750000, y=-13.250000}
Cocos2d: {x=-7.250000, y=-12.500000}
Hope it helps. :D
Using index for enumerating all array elements is correct, but I personally find it obsolete since C++11 range-for was introduced.
With C++11 you can enumerate values this way:
for(const auto& point : document["points"].GetArray()){
CCLOG("{x=%f, y=%f}", point["x"].GetDouble(), point["y"].GetDouble());
}
You can also enumerate object's fields the same way (if you need to):
for(const auto& field : point.GetObject()) {
field.name.GetString(); // Use field's name somehow...
field.value.GetDouble(); // Use field's value somehow...
}