本文整理汇总了C++中nlohmann::json::find方法的典型用法代码示例。如果您正苦于以下问题:C++ json::find方法的具体用法?C++ json::find怎么用?C++ json::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nlohmann::json
的用法示例。
在下文中一共展示了json::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromJson
void Pet::fromJson(nlohmann::json& val)
{
if(val.find("id") != val.end())
{
setId(val.at("id"));
}
if(val.find("category") != val.end())
{
if(!val["category"].is_null())
{
Category newItem(Category());
newItem.fromJson(val["category"]);
setCategory( newItem );
}
}
setName(val.at("name"));
{
m_PhotoUrls.clear();
nlohmann::json jsonArray;
for( auto& item : val["photoUrls"] )
{
m_PhotoUrls.push_back(item);
}
}
{
m_Tags.clear();
nlohmann::json jsonArray;
if(val.find("tags") != val.end())
{
for( auto& item : val["tags"] )
{
if(item.is_null())
{
m_Tags.push_back( Tag(nullptr) );
}
else
{
Tag newItem(Tag());
newItem.fromJson(item);
m_Tags.push_back( newItem );
}
}
}
}
if(val.find("status") != val.end())
{
setStatus(val.at("status"));
}
}
示例2: deserializeChatbotActions
void deserializeChatbotActions(const nlohmann::json& chatbot,
ChatbotActionModel& chatbotActionModel) {
nlohmann::json::const_iterator it;
it = chatbot.find("replies");
if (it != chatbot.end() && (*it).is_object()) {
deserializeReplies(*it, chatbotActionModel);
}
it = chatbot.find("replies_by_state_action");
if (it != chatbot.end() && (*it).is_object()) {
deserializeReplyIdsByStateAndActionId(*it, chatbotActionModel);
}
}
示例3: deserializeDictionaryModel
void deserializeDictionaryModel(const nlohmann::json& input,
DictionaryModel& dictionaryModel) {
nlohmann::json::const_iterator it = input.find("entities");
if (it != input.end() && (*it).is_object()) {
deserializeDictionary(*it, dictionaryModel);
}
}
示例4:
inline std::optional<nlohmann::json::const_iterator> find_json(const nlohmann::json& json,
const std::string& key) {
auto it = json.find(key);
if (it != std::end(json)) {
return it;
}
return std::nullopt;
}
示例5: set
void ExprFunction<T>::set(const nlohmann::json &j, const Tvarvec &vars) {
Tconstvec consts;
auto it = j.find("constants");
if (it != j.end())
for (auto i = it->begin(); i != it->end(); ++i)
consts.push_back({i.key(), i.value()});
set(j.at("function"), vars, consts);
}
示例6: deserializeChatbotActionModel
void deserializeChatbotActionModel(const nlohmann::json& input,
ChatbotActionModel& chatbotActionModel) {
nlohmann::json::const_iterator it;
it = input.find("chatbot");
if (it != input.end() && (*it).is_object()) {
deserializeChatbotActions(*it, chatbotActionModel);
}
}
示例7: deserializeIntentStoryModel
void deserializeIntentStoryModel(const nlohmann::json& input,
IntentStoryModel& intentStoryModel) {
nlohmann::json::const_iterator it;
it = input.find("intent_story");
if (it != input.end() && (*it).is_object()) {
deserializeIntentStory(*it, intentStoryModel);
}
}
示例8: deserializeIntentModel
void deserializeIntentModel(const nlohmann::json& input,
const DictionaryModel& dictionaryModel,
IntentModel& intentModel) {
nlohmann::json::const_iterator it = input.find("intents");
if (it != input.end() && (*it).is_array()) {
const nlohmann::json::array_t& intents = *it;
deserializeIntents(intents, dictionaryModel, intentModel);
}
}
示例9: isValid
bool BrokerMessage::isValid(const nlohmann::json& jsonObj) const
{
auto it = jsonObj.find("command");
if (it == jsonObj.end() ||
!it->is_string()) {
return false;
}
std::unordered_set<std::string> properties;
if (*it == "publish") {
properties = { "topics", "payload" };
}
else if (*it == "subscribe") {
properties = { "topics" };
}
else if (*it == "unsubscribe") {
properties = { "topics" };
}
else {
return false;
}
if (properties.find("topics") != properties.end()) {
it = jsonObj.find("topics");
if (it == jsonObj.end() ||
!it->is_array()) {
return false;
}
}
if (properties.find("payload") != properties.end()) {
it = jsonObj.find("payload");
if (it == jsonObj.end() ||
!it->is_string()) {
return false;
}
}
return true;
}
示例10: deserializeIntentStory
void deserializeIntentStory(const nlohmann::json& story,
IntentStoryModel& intentStoryModel) {
nlohmann::json::const_iterator it;
it = story.find("root");
if (it != story.end() && (*it).is_string()) {
IntentStoryModel::VertexInfo vInfo;
vInfo.stateId = *it;
IntentStoryModel::StoryGraph::Vertex v =
intentStoryModel.graph.addVertex(vInfo);
intentStoryModel.vertexByStateId[vInfo.stateId] = v;
intentStoryModel.rootStateId = vInfo.stateId;
}
it = story.find("graph");
if (it != story.end() && (*it).is_object()) {
deserializeGraph(*it, intentStoryModel);
}
}
示例11: find
inline std::optional<T> find(const nlohmann::json& json,
const std::string& key) {
auto it = json.find(key);
if (it != std::end(json)) {
try {
return it.value().get<T>();
} catch (std::exception&) {
}
}
return std::nullopt;
}
示例12: fromJson
void User::fromJson(nlohmann::json& val)
{
if(val.find("id") != val.end())
{
setId(val.at("id"));
}
if(val.find("username") != val.end())
{
setUsername(val.at("username"));
}
if(val.find("firstName") != val.end())
{
setFirstName(val.at("firstName"));
}
if(val.find("lastName") != val.end())
{
setLastName(val.at("lastName"));
}
if(val.find("email") != val.end())
{
setEmail(val.at("email"));
}
if(val.find("password") != val.end())
{
setPassword(val.at("password"));
}
if(val.find("phone") != val.end())
{
setPhone(val.at("phone"));
}
if(val.find("userStatus") != val.end())
{
setUserStatus(val.at("userStatus"));
}
}
示例13: check_equal
/*
* The check_equal function determines if the labels of the datanode and the querynode are equal.
* The function iterates through all the labels of the query node and compares its value to that of the datanode.
* It returns true only if all the labels match; returns false otherwises.
*/
bool check_equal(nlohmann::json datanode, nlohmann::json querynode) {
for (nlohmann::json::iterator it = querynode.begin(); it != querynode.end(); ++it) {
if ((it.key() != "id") && (it.key() != "out_degree")) {
if (datanode.find(it.key()) != datanode.end()) {
if(datanode[it.key()].is_string())
{
std::string d = datanode[it.key()], q= it.value();
if(d.find(q)== std::string::npos)
return false;
}
else if (datanode[it.key()] != it.value())
return false;
} else
return false;
}
}
return true;
}
示例14: Contains
bool Contains(const nlohmann::json& json, const std::string& member)
{
return json.is_object() && json.find(member) != json.end();
}
示例15: PrepareGrade
void Difference::PrepareGrade(const nlohmann::json& j) {
std::cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;
std::cout << "PREPARE GRADE" << std::endl;
// --------------------------------------------------------
//std::cout << "json " << j.dump(4) << std::endl;
if (j.find("max_char_changes") != j.end()) {
std::cout << "MAX CHAR CHANGES" << std::endl;
int max_char_changes = j.value("max_char_changes", -1);
assert (max_char_changes > 0);
int min_char_changes = j.value("min_char_changes",0);
assert (min_char_changes >= 0);
assert (min_char_changes < max_char_changes);
assert (total_char > 0);
if (max_char_changes > total_char) {
std::cout << "WARNING! max_char_changes > total_char)" << std::endl;
max_char_changes = total_char;
if (min_char_changes > max_char_changes) {
min_char_changes = max_char_changes-1;
}
assert (min_char_changes >= 0);
}
assert (max_char_changes <= total_char);
int char_changes = char_added + char_deleted;
std::cout << "char_changes=" << char_changes << " min=" << min_char_changes << " max=" << max_char_changes << std::endl;
int min_max_diff = max_char_changes-min_char_changes;
int lower_bar = std::max(0,min_char_changes-min_max_diff);
int upper_bar = max_char_changes + min_max_diff;
assert (0 <= lower_bar &&
lower_bar <= min_char_changes &&
min_char_changes <= max_char_changes &&
max_char_changes <= upper_bar);
float grade;
if (char_changes < lower_bar) {
std::cout << "too few char changes (zero credit)" << std::endl;
messages.push_back(std::make_pair(MESSAGE_FAILURE,"ERROR! Approx " + std::to_string(char_changes) + " characters added and/or deleted. Significantly fewer character changes than allowed."));
} else if (char_changes < min_char_changes) {
std::cout << "less than min char changes (partial credit)" << std::endl;
float numer = min_char_changes - char_changes;
float denom = min_max_diff;
std::cout << "numer " << numer << " denom= " << denom << std::endl;
assert (denom > 0);
grade = 1 - numer/denom;
messages.push_back(std::make_pair(MESSAGE_FAILURE,"ERROR! Approx " + std::to_string(char_changes) + " characters added and/or deleted. Fewer character changes than allowed."));
} else if (char_changes < max_char_changes) {
messages.push_back(std::make_pair(MESSAGE_SUCCESS,"Approx " + std::to_string(char_changes) + " characters added and/or deleted. Character changes within allowed range."));
std::cout << "between min and max char changes (full credit)" << std::endl;
grade = 1.0;
} else if (char_changes < upper_bar) {
std::cout << "more than max char changes (partial credit)" << std::endl;
float numer = char_changes - max_char_changes;
float denom = min_max_diff;
assert (denom > 0);
grade = 1 - numer/denom;
std::cout << "numer " << numer << " denom= " << denom << std::endl;
messages.push_back(std::make_pair(MESSAGE_FAILURE,"ERROR! Approx " + std::to_string(char_changes) + " characters added and/or deleted. More character changes than allowed."));
} else {
std::cout << "too many char changes (zero credit)" << std::endl;
messages.push_back(std::make_pair(MESSAGE_FAILURE,"ERROR! Approx " + std::to_string(char_changes) + " characters added and/or deleted. Significantly more character changes than allowed."));
grade = 0.0;
}
std::cout << "grade " << grade << std::endl;
assert (grade >= -0.00001 & grade <= 1.00001);
this->setGrade(grade);
}
// --------------------------------------------------------
else if (this->extraStudentOutputOk) {
// only missing lines (deletions) are a problem
int count_of_missing_lines = 0;
for (int x = 0; x < this->changes.size(); x++) {
int num_b_lines = this->changes[x].b_changes.size();
if (num_b_lines > 0) {
count_of_missing_lines += num_b_lines;
}
}
int output_length = this->output_length_b;
std::cout << "COMPARE outputlength=" << output_length << " missinglines=" << count_of_missing_lines << std::endl;
assert (count_of_missing_lines <= output_length);
float grade = 1.0;
if (output_length > 0) {
//std::cout << "SES [ESOO] calculating grade " << this->distance << "/" << output_length << std::endl;
//grade -= (this->distance / (float) output_length );
grade -= count_of_missing_lines / float(output_length);
std::cout <<
"grade: missing_lines [ " << count_of_missing_lines <<
"] / output_length " << output_length << "]\n";
//std::cout << "SES [ESOO] calculated grade = " << std::setprecision(1) << std::fixed << std::setw(5) << grade << " " << std::setw(5) << (int)floor(5*grade) << std::endl;
if (grade < 1.0 && this->only_whitespace_changes) {
std::cout << "ONLY WHITESPACE DIFFERENCES! adjusting grade: " << grade << " -> ";
// FIXME: Ugly, but with rounding, this will be only a -1 point grade for this test case
grade = std::max(grade,0.99f);
//.........这里部分代码省略.........