Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing json array of arrays #138

Open
jepessen opened this issue Aug 28, 2022 · 1 comment
Open

Parsing json array of arrays #138

jepessen opened this issue Aug 28, 2022 · 1 comment

Comments

@jepessen
Copy link

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;
};
@jgaa
Copy link
Owner

jgaa commented Aug 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants