restc-cpp
restc-cpp copied to clipboard
Parsing json array of arrays
I made a request, and the reply body is
[[1618160400,0.0000958,0.0000983,0.000096,0.0000976,14170.94],[1618156800,0.0000956,0.000098,0.0000956,0.0000959,12175.8],[1618153200,0.0000948,0.0000964,0.0000953,0.0000956,2815.79],[1618149600,0.0000948,0.0000957,0.0000948,0.0000951,1451.8],[1618146000,0.0000943,0.0000953,0.0000951,0.0000947,2114.07],[1618142400,0.0000934,0.0000954,0.0000942,0.0000954,3783.13]]
It's a JSON array, and every array element is an array itself, where the first value is an integer, and other five values are doubles. How can I parse it using the IteratorFromJsonSerializer in a struct like
struct MyData {
int v1;
double v2;
double v3;
double v4;
double v5;
double v6;
};
I think you'll have to read each element into a std::vector<double>. That's what they are sending. From there you can probably use boost.fusion to convert it nicely into a struct, but unless you know boost.fusion well it's probably simpler to just write a function that does the conversion.