-
I have a request coming in as JSON, Example: The std::string contains the Here is something I tried out: using json = nlohmann::json;
json::parser_callback_t json_cb = [](int depth, json::parse_event_t event, json& parsed){
if(event == json::parse_event_t::key and parsed == json("hello")){
return true;
}else{
return false;
}
};
// Here, INPUT_TEXT is std::string type (which is converted from char* to std::string from raw socket read() )
auto parsed_json = json::parse(INPUT_TEXT, json_cb);
std::cout << parsed_json << std::endl; For the note, But this keeps giving me NULL. Can someone help me figure this out? Or is there any other way I can parse this other than callback (I dont fully understand the use of callbacks in the json::parser, Im copy-pasting from docs? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can just call |
Beta Was this translation helpful? Give feedback.
You can just call
auto parse_json = json::parse(INPUT_TEXT);
. The callback is optional, and you may only need it if you want to filter values while parsing.