-
Notifications
You must be signed in to change notification settings - Fork 891
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
Return json in response of apis ? #263
Comments
json
of any method ?
There are few ways you can do it. Simples is to just dump it as a string: You can also define your own respnse:
And then return it. I'm using the same json library as you. You can have a look how I do it: https://github.com/moneroexamples/onion-monero-blockchain-explorer/blob/master/main.cpp Might find something that will help you. |
@moneroexamples :I am trying to return
Do you have any idea, how it can be resolved ? |
Can you show code sample? And maybe full error text? |
@mrozigor : Sure
And Error is coming in the 3rd last line of above code, where I am trying to convert UDT to |
Based on other responses in nlohmann's JSON library you should implement method 'from_json' outside class: void from_json(const nlohmann::json& j, Employer_access_detail& d) {
d.user_id = j.at("user_id");
d.auth_token = j.at("auth_token");
} |
Sadly nlohmann json library doesn't support user defined datatype of json. One can read more about it here |
Add `get_remote_ip` method to `websocket::connection`
I am using nlohmann json library in my crow project. Below is my sample POST method.
2nd last line of my code produces error because error: call of overloaded ‘response(json&)’ is ambiguous.
When I replace it with
return crow::response(return_json.dump());
it works perfectly, because this converts the json to string type. I would like to know, how can I return the actual json in response of my apis.The text was updated successfully, but these errors were encountered: