C++ - Convert JSON or array from it into vector C++ - Convert JSON or array from it into vector json json

C++ - Convert JSON or array from it into vector


The json parser has overloaded the [] operator to accept an integer for a JSON array. So it's accessed in the same way as a vector, but the underlying data structure doesn't have much in common. So you need to push it back into an std:::vector. You'll also want to convert the fields from JSON to something more C++ like if you want to use the data elsewhere. Something like {int id, std::string title, int quantity, float price};

Then you will have it as flat C++ list of structures in memory with a thin std::vector wrapper over it.