Wednesday, January 16, 2013

How to access the first element of an Json::Value array

To access the first element of an Json::Value array the following code may not work:
...
double x = point[0].asDouble()
...
Instead you have to write:
...
double x = point[0u].asDouble()
...
To find out why just check the following fragment of the Json::Value documentation:
const Value & operator[] (int index) const
Access an array element (zero based index)
You may need to say 'value[0u]' to get your compiler to distinguish this from the operator[] which takes a string.

No comments:

Post a Comment