-
Hello! I'm writing a an http server in which Im using this JSON lib for parsing the "application/json" data. Here is my cURL command to send a request to me server. $ curl -v -H "Content-Type: application/json" -d '{"value_one":123, "value_two":"foo_value"}' http://localhost:8766/poster And here is the function where I'm parsing the JSON std::string call_back(const std::string& user_agent_request_body){
try{
using json = nlohmann::json;
auto parsed_json = json::parse(user_agent_request_body.c_str());
int int_value = parsed_json["value_one"];
std::string string_value = parsed_json["value_two"];
std::string returner = "value_one: " + std::to_string(int_value) + " value_two: " + string_value;
return returner;
}catch(const std::exception& e){
std::cout << e.what() << std::endl;
std::string returner_exception = "Invalid POST data to JSON endpoint";
return returner_exception;
}
} For context,
I don't know if Im doing something wrong, Can someone please help me with this issue? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Can you make sure the string is properly terminated? The exception states that at byte 43 there is some garbage. |
Beta Was this translation helpful? Give feedback.
Can you make sure the string is properly terminated? The exception states that at byte 43 there is some garbage.