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

How to handle std::vector<std::uint8_t> #1930

Closed
ntoskrnl-exe opened this issue Feb 9, 2020 · 2 comments
Closed

How to handle std::vector<std::uint8_t> #1930

ntoskrnl-exe opened this issue Feb 9, 2020 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@ntoskrnl-exe
Copy link

I have built my own sockets layer, which works for an application I am working on.

The response from the Send returns a "complex" type containing the following data

std::vector<std::string> headers;
std::vector<std::uint8_t> body;

The reason the complex type represents the body as vector of bytes is the api will also transfer binary data as well as JSON string data.

My problem is when I do HTTP post, my data is sent correctly to the server. It updates the database, and then returns to my client. In the response, there is JSON data. I am trying to work out how to construct a JSON "object" that I can call contains to query the structured information for the certain returned data.

I have tried

nlohman::json _json(_response.body);

but it appears unable to find the nodes when I query the using contains. I have manually tried converting the vector of bytes to a string and parsing that, to no available.

I guess what I am asking for, is what section of the help should I look at more closely, to find the solution.

@nickaein
Copy link
Contributor

nickaein commented Feb 9, 2020

Hello Elliot Alderson,

How about something like

nlohmann::json j;
j = nlohmann::json::parse(response.body.begin(), response.body.end());

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Feb 15, 2020
@stale
Copy link

stale bot commented Mar 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

3 participants